I have been looking all over for a solution to this VBA autofiltering issue, any ideas are appreciated:
I have a static list of autofilter criteria in a named range "FslList" - which i have converted into one dimention array for autofiltering column 14 in a data worksheet:
Dim FSLArray As Variant
Dim rngFSL As Range
Set rngFSL = RawData.Worksheets(1).Range("FslList")
FSLArray = rngFSL.Value
With NewBook.Worksheets(1)
.Cells.AutoFilter Field:=14, Criteria1:=Application.Transpose(FSLArray), Operator:=xlFilterValues
Once i filter out the values from the array - i need to delete them
With .AutoFilter.Range
Set DeleteRange = .Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
End With
DeleteRange.EntireRow.Delete
NewBook.Worksheets(1).AutoFilterMode = False
End With
My issue is that my list of data is allways changing, and not all the values from FSLArray are in the column to be filtered. Thus the autofilter stops, once it encounters a criteria that is not on the list - and does not include any following criteria when filtering.
What i would like to do is for the autofilter to continue filtering using other array criteria, if one or more of the elements in the array, is not found amongst the data to be filtered.
EDIT: i have changed the data in my array from numbers (which it is) to letters - it works fine with letters now.
I have tried re-writing the code and define a named range as suggested:
Elements i have in the array (range C11:C14) are:
Acc
9158
11958 (this one is not present in the list of data)
15938
15940
The named range "PODCustList" is defined as follows:
=OFFSET(Acc,1,0,COUNTA(Settings!$C:$C)-1,1)
The code is the same:
Dim PODCustArray As Variant
Dim rngPODCust As Range
Set rngPODCust = RawData.Worksheets(1).Range("PODCustList")
PODCustArray = rngPODCust.Value
With Worksheets(1)
.Cells.AutoFilter Field:=7, Criteria1:=Application.Transpose(PODCustArray), Operator:=xlFilterValues
What i get in return after filtering is only rows with "9158" element in them filtered.
SOLVED: I needed to run my array through this - Criteria1:=Split(Join(Application.Transpose(PODCustArray))) for autofilter to correctly interpret the data within as a string array.
Can i adapt my code, or do i need to use a different approach?
Thank you in advance,


