Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default Toggle Autofilter

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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default Toggle Autofilter

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.


  #3   Report Post  
Posted to microsoft.public.excel.programming
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.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Toggle Autofilter

Dave

ToolsMacroRecord New Macro.

Record yourself while doing the above.


Gord Dibben MS Excel MVP

On Mon, 28 Aug 2006 13:12:01 -0700, 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.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default Toggle Autofilter

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.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default Toggle Autofilter

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.




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Toggle Autofilter

It needs to be Filters(8).On.
Try this:

Sub ToggleAutoFilter()
If Not Sheet1.AutoFilterMode Then
Sheet1.Range("H1").AutoFilter
End If
If Not Range("H1").Parent.AutoFilter.Filters(8).On Then
Range("H1").AutoFilter Field:=8, Criteria1:="="
Else
Range("H1").AutoFilter Field:=8
End If
End Sub

Mike F
"Die_Another_Day" wrote in message
ups.com...
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.





  #8   Report Post  
Posted to microsoft.public.excel.programming
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.




  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default Toggle Autofilter

Thanks, but I'm looking for an If Statement that would allow a button to
toggle the filter on/off.

"Gord Dibben" wrote:

Dave

ToolsMacroRecord New Macro.

Record yourself while doing the above.


Gord Dibben MS Excel MVP

On Mon, 28 Aug 2006 13:12:01 -0700, 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.



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Toggle Autofilter

It needs to be Filters(8).On.
Try this:

Sub ToggleAutoFilter()
If Not Sheet1.AutoFilterMode Then
Sheet1.Range("H1").AutoFilter
End If
If Not Range("H1").Parent.AutoFilter.Filters(8).On Then
Range("H1").AutoFilter Field:=8, Criteria1:="="
Else
Range("H1").AutoFilter Field:=8
End If
End Sub

Mike F

"Dave" wrote in message
...
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.





  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default Toggle Autofilter

Thanks very much to all for the help!
It's working well.

"Mike Fogleman" wrote:

It needs to be Filters(8).On.
Try this:

Sub ToggleAutoFilter()
If Not Sheet1.AutoFilterMode Then
Sheet1.Range("H1").AutoFilter
End If
If Not Range("H1").Parent.AutoFilter.Filters(8).On Then
Range("H1").AutoFilter Field:=8, Criteria1:="="
Else
Range("H1").AutoFilter Field:=8
End If
End Sub

Mike F

"Dave" wrote in message
...
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.




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel 2007 autofilter change to 2003 autofilter functionality? jonnybrovo815 Excel Discussion (Misc queries) 1 April 19th 10 10:05 PM
2007 excel autofilter change back to 2003 autofilter? jonnybrovo815 Excel Discussion (Misc queries) 1 April 19th 10 05:53 PM
Autofilter toggle problem CLR Excel Programming 6 April 19th 06 01:44 PM
Pesky Autofilter Toggle Digory[_2_] Excel Programming 0 November 16th 04 12:11 AM
Pesky Autofilter Toggle Digory Excel Programming 4 November 14th 04 03:06 PM


All times are GMT +1. The time now is 09:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"