使用VBA按数组值过滤excel列

时间:2017-12-20 21:55:43

标签: excel vba

我有一个excel列,其中包含应用程序代码,后跟应用程序的简短描述(BF00帐户应用程序)。该列很长,有很多应用,我只想通过应用代码过滤此列。这是我创建的方法,但它似乎不起作用:/

Private Sub FilterAppCodes()
Dim unfilter As Worksheet
Dim FindOutArray() As String
Dim iRow As Double
Dim CodeDef As Variant
Dim AppCodes As Variant
AppCodes = Array("A0A0", "B03B"....)
Dim iTotRecsA As Double
iRow = 2
Set unfilter = ThisWorkbook.Sheets(UN_FILTERED_SHEET)
iTotRecsA = unfilter.Range(ID_NUM & Rows.Count).End(xlUp).row

'Use a while loop to loop through the first sheet until Id's are blank
While unfilter.Cells(iRow, 1) <> ""

'Load all App codes & description in CodeDef
CodeDef = unfilter.Cells(iRow, 5)
Debug.Print (CodeDef)

    iRow = iRow + 1
Wend
FindOutArray = filter(SourceArray:=CodeDef, _
       Match:=AppCodes, _
       Include:=True, _
       Compare:=vbTextCompare)
    If UBound(FindOutArray) = -1 Then
        Debug.Print ("No, Array doesn't contain this item - " & strText)
    Else
        Debug.Print ("Yes, Array contains this item - " & strText)
    End If
End Sub

我在CodeDef变体中加载了所有列数据,并尝试将其与数组中的值进行比较。我想知道这是不对的?我在FindOutArray =过滤器上遇到“类型不匹配”错误(SourceArray .... part。

非常感谢任何帮助

0 个答案:

没有答案