我正在检索特定列的所有值并将所有值存储在一个数组中,以便我可以使用这些值来应用自动过滤器。
rowcount=objExcel.Activeworkbook.Sheets(1).UsedRange.Rows.count
Dim a()
Redim Preserve a(rowcount)
'msgbox rowcount
'Storing all column values in an array'
for i=2 to rowcount
a(i-2) = objSrcWorksheet.Cells(i,7).Value
Next
'Checking values of array'
for i=2 to rowcount
msgbox a(i-2)
'Applying Autofilter'
With objSrcWorksheet
.Range("G1").AutoFilter 2,"=a(i-2)" 'Problem is here'
'.Range("G1").AutoFilter 2,"=2" 'While hardcoded values are working'
End With
Next