VB Code to display AutoFilter selection

JPM

Active Member
Joined
Aug 1, 2002
Messages
407
I don't seem to get anyway with my other request http://www.mrexcel.com/board2/viewtopic.php?t=179802 so I am thinking about going the VB route.

My situation is, that I have a list with AutoFilter and need to display in a label or heading in a graph that shows what selection on the filter has been made.

Anyone who can help -- please?
Thx,
JPM
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Well nevermind, I figured a way by using a function:

Function AutoFilterCriteria() As String
Dim F As Long, sTemp As String


Application.Volatile


sTemp = ""
With ActiveSheet
If .AutoFilterMode = False Then Exit Function
If .FilterMode = False Then Exit Function


With .AutoFilter.Filters
For F = 1 To .Count
With .Item(F)
If .On Then
sTemp = .Criteria1
If .Operator = 1 Then
sTemp = sTemp & " and " & .Criteria2
ElseIf .Operator = 2 Then
sTemp = sTemp & " or " & .Criteria2
End If
Exit For
End If
End With
Next F
End With
End With


Done:
AutoFilterCriteria = sTemp
End Function
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,521
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top