View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Die_Another_Day Die_Another_Day is offline
external usenet poster
 
Posts: 644
Default Toggle Autofilter

I had to modify it slightly to handle the "All" Case without generating
an error.
Sub ToggleAutoFilter()
If Not Range("H1").Parent.AutoFilter.Filters(1).On Then
Range("H1").AutoFilter Field:=8, Criteria1:="="
Else
Range("H1").AutoFilter Field:=8
End If
End Sub

Charles

Die_Another_Day wrote:
Try this:
Sub ToggleAutoFilter()
If Range("H1").Parent.AutoFilter.Filters(1).Criteria1 = "=" Then
Range("H1").AutoFilter Field:=8
Else
Range("H1").AutoFilter Field:=8, Criteria1:= "="
End If
End Sub

Place a button on your sheet from the Forms toolbar and choose the
macro "ToggleAutoFilter" to run when clicked.

Charles

Dave wrote:
I'd like to display all of a list -or- only records with blank cells in the
8th column.
What code could I assign to a button that would toggle an autofilter?
Thank you.