Forum

Revise VBA Filter t...
 
Notifications
Clear all

Revise VBA Filter to become an On/Off Toggle

2 Posts
2 Users
0 Reactions
130 Views
(@webbers)
Posts: 148
Reputable Member
Topic starter
 

I have a VBA macro, which works.  Now when the autofilter exists, but is showing ALL data or there is no autofilter present, the macro below goes to my sheet ("Owner_CAPA"), and applies the filter so that only "no" values are visibble in column U (21st column).  Now what I would like to do, is revise this macro, so that if it currently displays only "No", and the macro button is pressed AGAIN, then it would go to "Show all data".  I know how to do this in 2 seperate macros, however not as a "toggle"

 

Sub FilterRowsOwner()

' Sheet = "Owner_CAPA", Column = U/#21
Worksheets("Owner_CAPA").Range("U1").AutoFilter Field:=21, Criteria1:="No"

End Sub

 
Posted : 16/02/2024 5:49 pm
(@keebellah)
Posts: 373
Reputable Member
 

Hi Sherry,

Give this a try

Sub FilterRowsOwner()

' Sheet = "Owner_CAPA", Column = U/#21
Select case Worksheetfunction.CountA(Worksheets("Owner_CAPA").Range("U:U")) = Worksheetfunction.Count(Worksheets("Owner_CAPA").Range("U:U"))
Case = True
Worksheets("Owner_CAPA").Range("U1").AutoFilter Field:=21, Criteria1:="No"
Case elee
Worksheets("Owner_CAPA").Range("U1").AutoFilter Field:=21
End Select
End Sub

 
Posted : 17/02/2024 2:50 am
Share: