I'm trying to use a Dictionary to populate a multiple wildcard AutoFilter for a which is captured from a table array. The capture seems to work fine however when it gets to applying the AutoFilter I get a Run-Time 448 'Named argument not found' error.
The data to be filtered is on a sheet called "FOLIOS" and is populated with headers from A1:P1 (with the filter to be applied to the data in column P. Column P contains various email addresses and I'm trying to filter them based on the domain names stored in tblOTA located on the "HDATA" sheet.
Any help would be very appreciated (Excel 365)
The table containing the criteria is named tblOTA (below) and already has the wildcard prefix "*" stored before the domain name:
Here is the code:
The data to be filtered is on a sheet called "FOLIOS" and is populated with headers from A1:P1 (with the filter to be applied to the data in column P. Column P contains various email addresses and I'm trying to filter them based on the domain names stored in tblOTA located on the "HDATA" sheet.
Any help would be very appreciated (Excel 365)
The table containing the criteria is named tblOTA (below) and already has the wildcard prefix "*" stored before the domain name:
tblOTA |
---|
*@central.com |
*@guest.com |
*@test.com |
Here is the code:
Rich (BB code):
Sub test()
'
' TEST Macro
'
'
Dim WB As Workbook: Set WB = ThisWorkbook
Dim aARRs As Variant
Dim OTA As ListObject
Dim dVALs As Object
Dim a As Long
Set OTA = Sheets("HDATA").ListObjects("tblOTA")
Set dVALs = CreateObject("Scripting.Dictionary")
dVALs.CompareMode = vbTextCompare
With Sheets("FOLIOS")
If .AutoFilterMode Then .AutoFilterMode = False
'Create Array List from Table
aARRs = OTA.DataBodyRange
For a = LBound(aARRs, 1) + 1 To UBound(aARRs, 1)
dVALs.Add Key:=aARRs(a, 1), Item:=aARRs(a, 1)
Next a
'test the array
'Dim k As Variant
'For Each k In dVALs.Keys
'Debug.Print k & " - " & dVALs.Item(k)
'Next k
'filter on column P if dictionary keys exist -- (Run time error occurs here)
If CBool(dVALs.Count) Then _
.AutoFilter Field:=16, Criteria1:=dVALs.keys, _
Operator:=xlFilterValues, VisibleDropDown:=False
If .AutoFilterMode Then .AutoFilterMode = False
End With
dVALs.RemoveAll: Set dVALs = Nothing
End Sub
Last edited by a moderator: