PC Review


Reply
Thread Tools Rate Thread

AutoFilter button

 
 
=?Utf-8?B?b2NlYW4=?=
Guest
Posts: n/a
 
      6th Nov 2006
Hello all! I need help creating a command button that applies a filter. I
don't want to use the drop down to select the filter everytime. I have to
use a customer filter and dont want to have the user to select the options
everytime. I just need a filter that displays the rows that contain the word
Yes or . in the D column. Any help would be greatly appreciated. Thanks in
advance
 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmF5?=
Guest
Posts: n/a
 
      6th Nov 2006
Hi Ocean-

Start the macro recorder and then build your autofilter. Stop the macro
recorder and view the result. With a tiny bit of tinkering, you'll have your
code.
--
Jay


"ocean" wrote:

> Hello all! I need help creating a command button that applies a filter. I
> don't want to use the drop down to select the filter everytime. I have to
> use a customer filter and dont want to have the user to select the options
> everytime. I just need a filter that displays the rows that contain the word
> Yes or . in the D column. Any help would be greatly appreciated. Thanks in
> advance

 
Reply With Quote
 
=?Utf-8?B?b2NlYW4=?=
Guest
Posts: n/a
 
      6th Nov 2006
Thanks Jay. That worked great. I have that recorded macro tied to a button
on the sheet now. Is there a way to toggle this back to unfiltered by
clicking the button again?

"Jay" wrote:

> Hi Ocean-
>
> Start the macro recorder and then build your autofilter. Stop the macro
> recorder and view the result. With a tiny bit of tinkering, you'll have your
> code.
> --
> Jay
>
>
> "ocean" wrote:
>
> > Hello all! I need help creating a command button that applies a filter. I
> > don't want to use the drop down to select the filter everytime. I have to
> > use a customer filter and dont want to have the user to select the options
> > everytime. I just need a filter that displays the rows that contain the word
> > Yes or . in the D column. Any help would be greatly appreciated. Thanks in
> > advance

 
Reply With Quote
 
=?Utf-8?B?SmF5?=
Guest
Posts: n/a
 
      6th Nov 2006
Hi Ocean -

Try the following, but first name the upper left-most cell of your list
"oceanHomeCell" (Insert, Name, Define). That just gives the code an
unambiguous reference point. Also, use the Control Toolbox to add a toggle
button to the worksheet. Good luck!

Private Sub ToggleButton1_Click()

If ActiveSheet.FilterMode = True Then
[oceanHomeCell].AutoFilter
[oceanHomeCell].AutoFilter
ActiveSheet.ToggleButton1 = False
ActiveSheet.ToggleButton1.Caption = "Push To Filter"
Exit Sub
End If

If ActiveSheet.AutoFilterMode = True Then
[oceanHomeCell].AutoFilter Field:=1, Criteria1:=">5", Operator:=xlOr, _
Criteria2:="<3" <<<<==========Change criteria to suit
ActiveSheet.ToggleButton1 = True
ActiveSheet.ToggleButton1.Caption = "Push To Remove Filter"
End If

End Sub
--
Jay


"ocean" wrote:

> Thanks Jay. That worked great. I have that recorded macro tied to a button
> on the sheet now. Is there a way to toggle this back to unfiltered by
> clicking the button again?
>
> "Jay" wrote:
>
> > Hi Ocean-
> >
> > Start the macro recorder and then build your autofilter. Stop the macro
> > recorder and view the result. With a tiny bit of tinkering, you'll have your
> > code.
> > --
> > Jay
> >
> >
> > "ocean" wrote:
> >
> > > Hello all! I need help creating a command button that applies a filter. I
> > > don't want to use the drop down to select the filter everytime. I have to
> > > use a customer filter and dont want to have the user to select the options
> > > everytime. I just need a filter that displays the rows that contain the word
> > > Yes or . in the D column. Any help would be greatly appreciated. Thanks in
> > > advance

 
Reply With Quote
 
=?Utf-8?B?b2NlYW4=?=
Guest
Posts: n/a
 
      7th Nov 2006
Thanks a ton for the help Jay. I placed an embeded toggle button on my sheet
and named the cell as you advised. I placed the code in Sheet1 as follows
but it will will not do anything. No errors either

Private Sub ToggleButton1_Click()
If ActiveSheet.AutoFilterMode = True Then
[oceanHomeCell].AutoFilter
[oceanHomeCell].AutoFilter
ActiveSheet.ToggleButton1 = False
ActiveSheet.ToggleButton1.Caption = "Push To Filter"
Exit Sub
End If

If ActiveSheet.AutoFilterMode = True Then
[oceanHomeCell].AutoFilter Field:=4, Criteria1:="=Yes", Operator:=xlOr, _
Criteria2:="=."
ActiveSheet.ToggleButton1 = True
ActiveSheet.ToggleButton1.Caption = "Push To Remove Filter"
End If

End Sub


"Jay" wrote:

> Hi Ocean -
>
> Try the following, but first name the upper left-most cell of your list
> "oceanHomeCell" (Insert, Name, Define). That just gives the code an
> unambiguous reference point. Also, use the Control Toolbox to add a toggle
> button to the worksheet. Good luck!
>
> Private Sub ToggleButton1_Click()
>
> If ActiveSheet.FilterMode = True Then
> [oceanHomeCell].AutoFilter
> [oceanHomeCell].AutoFilter
> ActiveSheet.ToggleButton1 = False
> ActiveSheet.ToggleButton1.Caption = "Push To Filter"
> Exit Sub
> End If
>
> If ActiveSheet.AutoFilterMode = True Then
> [oceanHomeCell].AutoFilter Field:=1, Criteria1:=">5", Operator:=xlOr, _
> Criteria2:="<3" <<<<==========Change criteria to suit
> ActiveSheet.ToggleButton1 = True
> ActiveSheet.ToggleButton1.Caption = "Push To Remove Filter"
> End If
>
> End Sub
> --
> Jay
>
>
> "ocean" wrote:
>
> > Thanks Jay. That worked great. I have that recorded macro tied to a button
> > on the sheet now. Is there a way to toggle this back to unfiltered by
> > clicking the button again?
> >
> > "Jay" wrote:
> >
> > > Hi Ocean-
> > >
> > > Start the macro recorder and then build your autofilter. Stop the macro
> > > recorder and view the result. With a tiny bit of tinkering, you'll have your
> > > code.
> > > --
> > > Jay
> > >
> > >
> > > "ocean" wrote:
> > >
> > > > Hello all! I need help creating a command button that applies a filter. I
> > > > don't want to use the drop down to select the filter everytime. I have to
> > > > use a customer filter and dont want to have the user to select the options
> > > > everytime. I just need a filter that displays the rows that contain the word
> > > > Yes or . in the D column. Any help would be greatly appreciated. Thanks in
> > > > advance

 
Reply With Quote
 
=?Utf-8?B?SmF5?=
Guest
Posts: n/a
 
      7th Nov 2006
Hi Ocean -

In the second line, change the word "Autofiltermode" to "Filtermode".

--
Jay


"ocean" wrote:

> Thanks a ton for the help Jay. I placed an embeded toggle button on my sheet
> and named the cell as you advised. I placed the code in Sheet1 as follows
> but it will will not do anything. No errors either
>
> Private Sub ToggleButton1_Click()
> If ActiveSheet.AutoFilterMode = True Then
> [oceanHomeCell].AutoFilter
> [oceanHomeCell].AutoFilter
> ActiveSheet.ToggleButton1 = False
> ActiveSheet.ToggleButton1.Caption = "Push To Filter"
> Exit Sub
> End If
>
> If ActiveSheet.AutoFilterMode = True Then
> [oceanHomeCell].AutoFilter Field:=4, Criteria1:="=Yes", Operator:=xlOr, _
> Criteria2:="=."
> ActiveSheet.ToggleButton1 = True
> ActiveSheet.ToggleButton1.Caption = "Push To Remove Filter"
> End If
>
> End Sub
>
>
> "Jay" wrote:
>
> > Hi Ocean -
> >
> > Try the following, but first name the upper left-most cell of your list
> > "oceanHomeCell" (Insert, Name, Define). That just gives the code an
> > unambiguous reference point. Also, use the Control Toolbox to add a toggle
> > button to the worksheet. Good luck!
> >
> > Private Sub ToggleButton1_Click()
> >
> > If ActiveSheet.FilterMode = True Then
> > [oceanHomeCell].AutoFilter
> > [oceanHomeCell].AutoFilter
> > ActiveSheet.ToggleButton1 = False
> > ActiveSheet.ToggleButton1.Caption = "Push To Filter"
> > Exit Sub
> > End If
> >
> > If ActiveSheet.AutoFilterMode = True Then
> > [oceanHomeCell].AutoFilter Field:=1, Criteria1:=">5", Operator:=xlOr, _
> > Criteria2:="<3" <<<<==========Change criteria to suit
> > ActiveSheet.ToggleButton1 = True
> > ActiveSheet.ToggleButton1.Caption = "Push To Remove Filter"
> > End If
> >
> > End Sub
> > --
> > Jay
> >
> >
> > "ocean" wrote:
> >
> > > Thanks Jay. That worked great. I have that recorded macro tied to a button
> > > on the sheet now. Is there a way to toggle this back to unfiltered by
> > > clicking the button again?
> > >
> > > "Jay" wrote:
> > >
> > > > Hi Ocean-
> > > >
> > > > Start the macro recorder and then build your autofilter. Stop the macro
> > > > recorder and view the result. With a tiny bit of tinkering, you'll have your
> > > > code.
> > > > --
> > > > Jay
> > > >
> > > >
> > > > "ocean" wrote:
> > > >
> > > > > Hello all! I need help creating a command button that applies a filter. I
> > > > > don't want to use the drop down to select the filter everytime. I have to
> > > > > use a customer filter and dont want to have the user to select the options
> > > > > everytime. I just need a filter that displays the rows that contain the word
> > > > > Yes or . in the D column. Any help would be greatly appreciated. Thanks in
> > > > > advance

 
Reply With Quote
 
=?Utf-8?B?SmF5?=
Guest
Posts: n/a
 
      7th Nov 2006
Hi Ocean -
Try this version. Copy/Paste into your Sheet1 object in the VB Editor.
This version does not require a pre-existing autofilter; if an autofilter
doesn't exist, it will start one.
-------
Private Sub ToggleButton1_Click()
'Filtermode=true if an autofilter is present and there are hidden rows
in its list.
'Reset the filter and update toggle button text.
If ActiveSheet.FilterMode = True Then
[oceanHomeCell].AutoFilter
[oceanHomeCell].AutoFilter
ActiveSheet.ToggleButton1.Caption = "Push To Filter"
Exit Sub
End If

'Autofilter is present, but all rows are visible OR the list has no
autofilter at all.
'Set the autofilter (with criteria) and update toggle button text.
[oceanHomeCell].AutoFilter Field:=4, Criteria1:="=Yes", Operator:=xlOr,
Criteria2:="=."
ActiveSheet.ToggleButton1.Caption = "Push To Remove Filter"
End Sub
-----
Jay


"Jay" wrote:

> Hi Ocean -
>
> In the second line, change the word "Autofiltermode" to "Filtermode".
>
> --
> Jay
>
>
> "ocean" wrote:
>
> > Thanks a ton for the help Jay. I placed an embeded toggle button on my sheet
> > and named the cell as you advised. I placed the code in Sheet1 as follows
> > but it will will not do anything. No errors either
> >
> > Private Sub ToggleButton1_Click()
> > If ActiveSheet.AutoFilterMode = True Then
> > [oceanHomeCell].AutoFilter
> > [oceanHomeCell].AutoFilter
> > ActiveSheet.ToggleButton1 = False
> > ActiveSheet.ToggleButton1.Caption = "Push To Filter"
> > Exit Sub
> > End If
> >
> > If ActiveSheet.AutoFilterMode = True Then
> > [oceanHomeCell].AutoFilter Field:=4, Criteria1:="=Yes", Operator:=xlOr, _
> > Criteria2:="=."
> > ActiveSheet.ToggleButton1 = True
> > ActiveSheet.ToggleButton1.Caption = "Push To Remove Filter"
> > End If
> >
> > End Sub
> >
> >
> > "Jay" wrote:
> >
> > > Hi Ocean -
> > >
> > > Try the following, but first name the upper left-most cell of your list
> > > "oceanHomeCell" (Insert, Name, Define). That just gives the code an
> > > unambiguous reference point. Also, use the Control Toolbox to add a toggle
> > > button to the worksheet. Good luck!
> > >
> > > Private Sub ToggleButton1_Click()
> > >
> > > If ActiveSheet.FilterMode = True Then
> > > [oceanHomeCell].AutoFilter
> > > [oceanHomeCell].AutoFilter
> > > ActiveSheet.ToggleButton1 = False
> > > ActiveSheet.ToggleButton1.Caption = "Push To Filter"
> > > Exit Sub
> > > End If
> > >
> > > If ActiveSheet.AutoFilterMode = True Then
> > > [oceanHomeCell].AutoFilter Field:=1, Criteria1:=">5", Operator:=xlOr, _
> > > Criteria2:="<3" <<<<==========Change criteria to suit
> > > ActiveSheet.ToggleButton1 = True
> > > ActiveSheet.ToggleButton1.Caption = "Push To Remove Filter"
> > > End If
> > >
> > > End Sub
> > > --
> > > Jay
> > >
> > >
> > > "ocean" wrote:
> > >
> > > > Thanks Jay. That worked great. I have that recorded macro tied to a button
> > > > on the sheet now. Is there a way to toggle this back to unfiltered by
> > > > clicking the button again?
> > > >
> > > > "Jay" wrote:
> > > >
> > > > > Hi Ocean-
> > > > >
> > > > > Start the macro recorder and then build your autofilter. Stop the macro
> > > > > recorder and view the result. With a tiny bit of tinkering, you'll have your
> > > > > code.
> > > > > --
> > > > > Jay
> > > > >
> > > > >
> > > > > "ocean" wrote:
> > > > >
> > > > > > Hello all! I need help creating a command button that applies a filter. I
> > > > > > don't want to use the drop down to select the filter everytime. I have to
> > > > > > use a customer filter and dont want to have the user to select the options
> > > > > > everytime. I just need a filter that displays the rows that contain the word
> > > > > > Yes or . in the D column. Any help would be greatly appreciated. Thanks in
> > > > > > advance

 
Reply With Quote
 
=?Utf-8?B?b2NlYW4=?=
Guest
Posts: n/a
 
      7th Nov 2006
Jay you are awesome! It works like a charm. Thanks a bunch kind sir

"Jay" wrote:

> Hi Ocean -
> Try this version. Copy/Paste into your Sheet1 object in the VB Editor.
> This version does not require a pre-existing autofilter; if an autofilter
> doesn't exist, it will start one.
> -------
> Private Sub ToggleButton1_Click()
> 'Filtermode=true if an autofilter is present and there are hidden rows
> in its list.
> 'Reset the filter and update toggle button text.
> If ActiveSheet.FilterMode = True Then
> [oceanHomeCell].AutoFilter
> [oceanHomeCell].AutoFilter
> ActiveSheet.ToggleButton1.Caption = "Push To Filter"
> Exit Sub
> End If
>
> 'Autofilter is present, but all rows are visible OR the list has no
> autofilter at all.
> 'Set the autofilter (with criteria) and update toggle button text.
> [oceanHomeCell].AutoFilter Field:=4, Criteria1:="=Yes", Operator:=xlOr,
> Criteria2:="=."
> ActiveSheet.ToggleButton1.Caption = "Push To Remove Filter"
> End Sub
> -----
> Jay
>
>
> "Jay" wrote:
>
> > Hi Ocean -
> >
> > In the second line, change the word "Autofiltermode" to "Filtermode".
> >
> > --
> > Jay
> >
> >
> > "ocean" wrote:
> >
> > > Thanks a ton for the help Jay. I placed an embeded toggle button on my sheet
> > > and named the cell as you advised. I placed the code in Sheet1 as follows
> > > but it will will not do anything. No errors either
> > >
> > > Private Sub ToggleButton1_Click()
> > > If ActiveSheet.AutoFilterMode = True Then
> > > [oceanHomeCell].AutoFilter
> > > [oceanHomeCell].AutoFilter
> > > ActiveSheet.ToggleButton1 = False
> > > ActiveSheet.ToggleButton1.Caption = "Push To Filter"
> > > Exit Sub
> > > End If
> > >
> > > If ActiveSheet.AutoFilterMode = True Then
> > > [oceanHomeCell].AutoFilter Field:=4, Criteria1:="=Yes", Operator:=xlOr, _
> > > Criteria2:="=."
> > > ActiveSheet.ToggleButton1 = True
> > > ActiveSheet.ToggleButton1.Caption = "Push To Remove Filter"
> > > End If
> > >
> > > End Sub
> > >
> > >
> > > "Jay" wrote:
> > >
> > > > Hi Ocean -
> > > >
> > > > Try the following, but first name the upper left-most cell of your list
> > > > "oceanHomeCell" (Insert, Name, Define). That just gives the code an
> > > > unambiguous reference point. Also, use the Control Toolbox to add a toggle
> > > > button to the worksheet. Good luck!
> > > >
> > > > Private Sub ToggleButton1_Click()
> > > >
> > > > If ActiveSheet.FilterMode = True Then
> > > > [oceanHomeCell].AutoFilter
> > > > [oceanHomeCell].AutoFilter
> > > > ActiveSheet.ToggleButton1 = False
> > > > ActiveSheet.ToggleButton1.Caption = "Push To Filter"
> > > > Exit Sub
> > > > End If
> > > >
> > > > If ActiveSheet.AutoFilterMode = True Then
> > > > [oceanHomeCell].AutoFilter Field:=1, Criteria1:=">5", Operator:=xlOr, _
> > > > Criteria2:="<3" <<<<==========Change criteria to suit
> > > > ActiveSheet.ToggleButton1 = True
> > > > ActiveSheet.ToggleButton1.Caption = "Push To Remove Filter"
> > > > End If
> > > >
> > > > End Sub
> > > > --
> > > > Jay
> > > >
> > > >
> > > > "ocean" wrote:
> > > >
> > > > > Thanks Jay. That worked great. I have that recorded macro tied to a button
> > > > > on the sheet now. Is there a way to toggle this back to unfiltered by
> > > > > clicking the button again?
> > > > >
> > > > > "Jay" wrote:
> > > > >
> > > > > > Hi Ocean-
> > > > > >
> > > > > > Start the macro recorder and then build your autofilter. Stop the macro
> > > > > > recorder and view the result. With a tiny bit of tinkering, you'll have your
> > > > > > code.
> > > > > > --
> > > > > > Jay
> > > > > >
> > > > > >
> > > > > > "ocean" wrote:
> > > > > >
> > > > > > > Hello all! I need help creating a command button that applies a filter. I
> > > > > > > don't want to use the drop down to select the filter everytime. I have to
> > > > > > > use a customer filter and dont want to have the user to select the options
> > > > > > > everytime. I just need a filter that displays the rows that contain the word
> > > > > > > Yes or . in the D column. Any help would be greatly appreciated. Thanks in
> > > > > > > advance

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hide Autofilter Button but keep the filter on vlad Microsoft Excel Programming 1 7th Mar 2008 12:21 AM
Execute Macro When any Built-in Autofilter Button is Pushed =?Utf-8?B?SmF5?= Microsoft Excel Programming 0 12th Mar 2006 08:43 PM
Autofilter reset button =?Utf-8?B?Q2hlZXNl?= Microsoft Excel Misc 6 9th Jul 2005 06:39 PM
autofilter button colour change gajewska@shaw.ca Microsoft Excel Misc 2 25th Aug 2004 05:25 AM
Autofilter hiding button bar Iain King Microsoft Excel Discussion 0 25th Jun 2004 04:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:15 AM.