开发者

VBA matching combobox values with ranges

I am trying to match the value in a combobox with values from a range and put matching values into an array. However, according to the watch window my array is not storing any values. I think there is something wrong with my reference to the combobox value but I am not sure how to correct it. Any input appreciated.

ILsearch is the name of my userform

AnSelect is the name of my combobox

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


This worked for me:

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜