The ultimate goal of this procedure is to delete all rows in the "TestData" table that have a user which is listed in the "SysAccts" table (on the "Lists" worksheet).
I'm using autofilter to find those rows so I can select them and delete them.
This is my code:
Sub ClearSystemAccts()
Dim wksData As Worksheet
Dim objDataTable As ListObject
Dim varSysAccts As Variant
Set wksData = ActiveWorkbook.Sheets("Test Data")
Set objDataTable = wksData.ListObjects("TestData")
varSysAccts = Worksheets("Lists").Range("SystemAccts")
With objDataTable.Range
'turn off the autofilters as a reset
.AutoFilter
'set the autofilter with the criteria;
.AutoFilter field:=2, Criteria1:=varSysAccts, Operator:=xlFilterValues
'Delete the entire row for the visible cells; _
'skips the header but also deletes the blank row below the table.
.CurrentRegion.Offset(1).EntireRow.Delete
'turn off autofilter
.AutoFilter
End With
End Sub
When I run the code, the autofilter display no rows in the table.
I have validated that the varSysAccts variable is properly populated.
When I hover over the criteria in the Autofilter line, I get the following:
I think the problem is that when a table is read into an array, it is always a dynamic array. But the table is only one column. How do I fix this?
EDITED: Per the comment below, I removed the array from the criteria. Now I don't get the type mismatch, but the filter still doesn't select any rows.