VBA将组合框值与范围匹配

时间:2011-07-13 09:07:42

标签: vba combobox

我试图将组合框中的值与范围中的值进行匹配,并将匹配值放入数组中。但是,根据监视窗口,我的数组不存储任何值。我认为我对组合框值的引用有问题,但我不确定如何纠正它。任何意见都赞赏。

ILsearch是我的用户表单的名称

AnSelect是我的组合框的名称

Dim ia As Long
Dim Anion As Range, AnFind As Range
Dim AnResults() As Variant

    If ILsearch.ICheck1.Value = True Then
    Set Anion = Worksheets("Properties").Range("T7:T600")
    For Each AnFind In Anion
        If AnFind.Value = ILsearch.AnSelect.Value Then
            ia = ia + 1
            ReDim Preserve AnResults(ia)
            AnResults(ia - 1) = AnFind.Row
        End If
    Next AnFind
    End If

1 个答案:

答案 0 :(得分:0)

这对我有用:

Dim ia As Long
Dim Anion As Range, AnFind As Range
Dim AnResults() As Variant

    ia = 0
    If ILsearch.ICheck1.Value = True Then
      Set Anion = Worksheets("Properties").Range("T7:T600")
      For Each AnFind In Anion.Cells
        If AnFind.Value = ILSearch.AnSelect.Value Then
            ia = ia + 1
            ReDim Preserve AnResults(1 To ia)
            AnResults(ia) = AnFind.Row
        End If
      Next AnFind

      MsgBox Join(AnResults, ",")
    End If