What are table filtering criteria? (As one of or an array of selected values ​​from the table column header drop-down list)

I have a table with multiple columns with automatic filtering.

One of my columns has automatic month filtering, which takes the following code.

ActiveSheet.ListObjects("Salary").Range.AutoFilter Field:= _
    Application.WorksheetFunction.Match("Mounth", Range("Salary[#Headers]"), 0), _
    Criteria1:="=09"

Sometimes I need to provide a value for the filter criteria of this column to assign a variable. Therefore, it is always unknown what the filtered value is.

Of course, the user can select more than one item from the table header menu drop-down list, as the code action is below:

ActiveSheet.ListObjects("Salary").Range.AutoFilter Field:= _
    Application.WorksheetFunction.Match("Mounth", Range("Salary[#Headers]"), 0), _
    Criteria1:="=09", Operator:=xlOr, Criteria2:="=08"

How can I catch all the ones selected in the array or make sure that the selected value is unique and assign it to the same variable?

-1
source share
1

.AutoFilter.Filters :

Dim list As ListObject, colIndex As Long, filter As Filter
Set list = ActiveSheet.ListObjects("Table1")
If list.ShowAutoFilter = False Then Exit Sub   ' filters are not on

colIndex = list.ListColumns("Month").Index
Set filter = list.AutoFilter.filters(colIndex)
If filter.On = False Then Exit Sub             ' no filter

Select Case filter.Operator
    Case 0:        Debug.Print filter.Criteria1                   ' no operator
    Case xlOr:     Debug.Print filter.Criteria1, filter.Criteria2
    Case xlValues: Debug.Print Join(filter.Criteria1)             ' array
    Case Else: Debug.Print filter.Operator, filter.Criteria1, filter.Criteria2 ' handle the rest of the operators
End Select
+1

Source: https://habr.com/ru/post/1686148/


All Articles