问题
From VBA I need to know the list of all criteria that I can choose in filtering columns. For example the following list: [1-ALFA;2-BETA;...5-ETC]
回答1:
Say we have data like:
and we filter size for large and we want to list the criteria for column A:
Sub ShowCriteria()
Dim r As Range, c1 As Collection, c2 As Collection
Dim msg As String
Set c1 = New Collection
Set c2 = New Collection
Dim LastRow As Integer
With Worksheets("sheet1")
LastRow = .Range("A" & Worksheets("sheet1").Rows.Count).End(xlUp).Row
End With
On Error Resume Next
For Each r In Range("A2:A" & LastRow)
v = r.Value
c1.Add v, CStr(v)
If r.EntireRow.Hidden = False Then
c2.Add v, CStr(v)
End If
Next
On Error GoTo 0
msg = "Full criteria"
For i = 1 To c1.Count
msg = msg & vbCrLf & c1.Item(i)
Next i
msg = msg & vbCrLf & vbCrLf & "Visible criteria"
For i = 1 To c2.Count
msg = msg & vbCrLf & c2.Item(i)
Next i
MsgBox msg
End Sub
Will display:
来源:https://stackoverflow.com/questions/29773987/get-all-list-of-possible-filter-criteria