I have gone down a rabbit hole with this and am probably going to be told I've gone about it the wrong way, but anyway:
I have a set of buttons that I want users to be able to press to automatically filter the dataset. The buttons should filter each column but each button should filter on top of whatever filters are already in place. I could use the normal auto-filter; however it appears I am limited (to 2?) text options. On top of this, i would ideally like the user to be able to write in their own text to be filtered in the future.
I have therefore built some dynamic named ranges in a separate sheet, that will expand automatically when the user types in additional text (i.e. text phrases that will be called upon for the filter). In the example below I have called one of these lists: "List_of_text_to_be_filtered_1"
In terms of which columns are being filtered at any one time, I have made another dynamic named range (to expand the range automatically to the end row), called "ColumnA":
Option Explicit
Sub Sort1()
With ActiveSheet
.Range("columnA").AdvancedFilter _
Action:=xlFilterInPlace, _
CriteriaRange:=Range("List_of_text_to_be_filtered_1")
End With
End Sub
The problem that I am encountering is that I have another set of code that basically identical, e.g.
Option Explicit
Sub Sort1()
With ActiveSheet
.Range("columnB").AdvancedFilter _
Action:=xlFilterInPlace, _
CriteriaRange:=Range("List_of_text_to_be_filtered_2")
End With
End Sub
But when the user runs this, the advanced filter gets reset and doesn't build on the last filter. Is there a way to build up on the last advanced filter?
Let me know if you want to see my dynamic named ranges formulas.
Thanks.
Edit:
I've changed it to auto-filter with an array but something still isn't working (it appears to be choosing every item on the list, yet nothing is being displayed):
Sub CellsToArray()
Dim x As Integer
Dim myArray As Variant, lastrow As Long
With Range("Names_backup")
intFirstCol = .Column
intlastcol = intFirstCol + .Columns.Count - 1
End With
With shLists
lastrow = .Cells(.Rows.Count, ("T")).End(xlUp).Row
End With
For x = Range("Names_backup").Row To lastrow
myArray = Cells(x, intlastcol).Value
x = x + 1
Next x
With Range("ColumnA")
intFirstCol = .Column
intlastcol = intFirstCol + .Columns.Count - 1
End With
Range("ColumnA").AutoFilter Field:=intlastcol, Criteria1:=Array(myArray), Operator:=xlFilterValues
End Sub
Where Names_Backup is the cell header containing the list of text words that should be used to filter. And "ColumnA" is the named range of the column I want to be filtered.