I am presently working with data from a mainframe, not unlike the data presented here. In this case, all I have are strings akin to 100-AAA for my criteria and for my target data set. I have searched for a similar solution, but I have not found a direct filter by range question for VBA on SO.
I am attempting to filter a large dataset based on a range of criteria. Originally, I started playing with collections in separate classes/subroutines, but then I compressed to the use of ranges within a single subroutine, as follows:
Sub FilterTest1()
Dim RngOne As Range
Dim LastCell As Long
Sheets("Criteria").Activate
Sheets("Criteria").Select
Range("A1").Select
LastCell = Application.WorksheetFunction.CountA(ActiveSheet.Range("A:A"))
Set RngOne = ActiveSheet.Range("A2:A" & LastCell)
Sheets("Sheet 1").Activate
Sheets("Sheet 1").Select
With ActiveSheet
If .FilterMode Then
.ShowAllData
End If
End With
Columns("A:A").Select
Selection.AutoFilter
ActiveSheet.Range("A:A").AutoFilter Field:=1, Criteria1:=RngOne, Operator:=xlOr
End Sub
Unfortunately, my range of cells does not filter the data, even when using criteria such as Operator:=xlOr
- it just displays the very last cell value used for the criteria. The VBA code does not fail - it just does not filter properly based on the range.
I feel certain that there exists a simple solution, but I cannot quite see it.