View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Dave Dave is offline
external usenet poster
 
Posts: 1,388
Default Toggle Autofilter

This version doesn't error but the If statement continues to return True
so that it never reaches the Else clause.


"Die_Another_Day" wrote:

It looks like you used the first code I posted, I caught my mistake and
reposted. Here it is again:
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

Try that version and let me know if you still have issues.

Charles

Dave wrote:
Perhaps I've omited some critical info.
I'm running Excel 2000 on WinXP.
My header row is B4:I4.
Autofilters are on. (Visible)
I've copied the code below changing "H1" to "I4"
When run, it errors on the 1st line 'If Range...'
Displays "Application-Defined or Object-Defined error"
Any suggestions?
Thanks.


"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.