Once again i am in trouble when trying to use array criteria in autofilters. Maybe someone will be able to solve it.
I have strings of criteria in an excel sheet in the following format: 12562,15215 (these are edited by users).
What i want to do is for a loop to take each cell containing these criteria and autofilter a certain field in another workbook using the cell contents as an array, then go to a next row of criteria.
The loop seems to be fine (i might be wrong) but when it comes to the autofilter, it does not find any cells. The string variable will not pass to the filter criteria array correctly (if i just hardcode the criteria to the filters - everything works).
Does my code contain some errors, or is the whole approach flawed?
Any assistance is appreciated.
Dim ExcRange As Range
Dim Col As Range
Dim Filter1 As Variant
With RawData.Worksheets(1)
.AutoFilterMode = False
End With
Dim Lastrow3 As Integer
Lastrow3 = RawData.Worksheets(1).Cells(Rows.Count, "O").End(xlUp).Row
Set ExcRange = RawData.Worksheets(1).Range("O11:O" & Lastrow3)
For Each Col In ExcRange
If Not Col Is Nothing Then
Filter1 = Split(Col.Value, ",")
With NewBook.Worksheets(1)
.Cells.AutoFilter Field:=1, Criteria1:=Array(Filter1), Operator:=xlFilterValues, Operator:=xlAnd
End With
Else
End If
Next Col
I have also tried coding the autofilters this way:
.Cells.AutoFilter Field:=5, Criteria1:=Filter1, Operator:=xlFilterValues, Operator:=xlAnd
ExcRangelike this12562or there are number with quotation marks like this"12562".