PC Review


Reply
Thread Tools Rate Thread

Check Auto Filter - if on, turn off before running macro

 
 
Munchkin
Guest
Posts: n/a
 
      24th Nov 2009
I can't figure out how to do this. Before my macro runs I want to check to
see if AutoFilter is turned on. If it is I want to turn it off - if it isn't
then do nothing.



Rows("2:4").Select
Selection.EntireRow.Hidden = False
Range("A2").Select
Selection.ClearContents

Range("I2").Select
'Application.Run "'NamedInsuredList 2 11-2009.xls'!CheckBoxFilter_Click"
Range("PolicyList").Sort Key1:=Range("A7"), Order1:=xlAscending,
Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers

Range("A2").Select
 
Reply With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      24th Nov 2009
You can test the AutoFilterMode property of the worksheet... it will be True
if the AutoFilter is active and False otherwise. You can set the property to
False in your code to turn AutoFilter'ing off (but you cannot set the
property to True to turn it back on though).

--
Rick (MVP - Excel)


"Munchkin" <(E-Mail Removed)> wrote in message
news:65530615-7598-4713-9A33-(E-Mail Removed)...
>I can't figure out how to do this. Before my macro runs I want to check to
> see if AutoFilter is turned on. If it is I want to turn it off - if it
> isn't
> then do nothing.
>
>
>
> Rows("2:4").Select
> Selection.EntireRow.Hidden = False
> Range("A2").Select
> Selection.ClearContents
>
> Range("I2").Select
> 'Application.Run "'NamedInsuredList 2
> 11-2009.xls'!CheckBoxFilter_Click"
> Range("PolicyList").Sort Key1:=Range("A7"), Order1:=xlAscending,
> Header:= _
> xlGuess, OrderCustom:=1, MatchCase:=False,
> Orientation:=xlTopToBottom, _
> DataOption1:=xlSortTextAsNumbers
>
> Range("A2").Select


 
Reply With Quote
 
Munchkin
Guest
Posts: n/a
 
      24th Nov 2009
Can you display the code? I don't know what it is & can't seem to be able to
figure it out.

"Rick Rothstein" wrote:

> You can test the AutoFilterMode property of the worksheet... it will be True
> if the AutoFilter is active and False otherwise. You can set the property to
> False in your code to turn AutoFilter'ing off (but you cannot set the
> property to True to turn it back on though).
>
> --
> Rick (MVP - Excel)
>
>
> "Munchkin" <(E-Mail Removed)> wrote in message
> news:65530615-7598-4713-9A33-(E-Mail Removed)...
> >I can't figure out how to do this. Before my macro runs I want to check to
> > see if AutoFilter is turned on. If it is I want to turn it off - if it
> > isn't
> > then do nothing.
> >
> >
> >
> > Rows("2:4").Select
> > Selection.EntireRow.Hidden = False
> > Range("A2").Select
> > Selection.ClearContents
> >
> > Range("I2").Select
> > 'Application.Run "'NamedInsuredList 2
> > 11-2009.xls'!CheckBoxFilter_Click"
> > Range("PolicyList").Sort Key1:=Range("A7"), Order1:=xlAscending,
> > Header:= _
> > xlGuess, OrderCustom:=1, MatchCase:=False,
> > Orientation:=xlTopToBottom, _
> > DataOption1:=xlSortTextAsNumbers
> >
> > Range("A2").Select

>
> .
>

 
Reply With Quote
 
J_Knowles
Guest
Posts: n/a
 
      25th Nov 2009
Here's what you need.

Sub AutoFilterSetToOff()
If ActiveSheet.AutoFilterMode = True Then
ActiveSheet.AutoFilterMode = False
End If
End Sub

HTH
--
Data Hog


"Munchkin" wrote:

> Can you display the code? I don't know what it is & can't seem to be able to
> figure it out.
>
> "Rick Rothstein" wrote:
>
> > You can test the AutoFilterMode property of the worksheet... it will be True
> > if the AutoFilter is active and False otherwise. You can set the property to
> > False in your code to turn AutoFilter'ing off (but you cannot set the
> > property to True to turn it back on though).
> >
> > --
> > Rick (MVP - Excel)
> >
> >
> > "Munchkin" <(E-Mail Removed)> wrote in message
> > news:65530615-7598-4713-9A33-(E-Mail Removed)...
> > >I can't figure out how to do this. Before my macro runs I want to check to
> > > see if AutoFilter is turned on. If it is I want to turn it off - if it
> > > isn't
> > > then do nothing.
> > >
> > >
> > >
> > > Rows("2:4").Select
> > > Selection.EntireRow.Hidden = False
> > > Range("A2").Select
> > > Selection.ClearContents
> > >
> > > Range("I2").Select
> > > 'Application.Run "'NamedInsuredList 2
> > > 11-2009.xls'!CheckBoxFilter_Click"
> > > Range("PolicyList").Sort Key1:=Range("A7"), Order1:=xlAscending,
> > > Header:= _
> > > xlGuess, OrderCustom:=1, MatchCase:=False,
> > > Orientation:=xlTopToBottom, _
> > > DataOption1:=xlSortTextAsNumbers
> > >
> > > Range("A2").Select

> >
> > .
> >

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      25th Nov 2009
If this is all the OP wants to do, then I would probably do away with the
test and simply always set it to False no matter what its current setting
is...

Sub AutoFilterSetToOff()
ActiveSheet.AutoFilterMode = False
End Sub

--
Rick (MVP - Excel)


"J_Knowles" <(E-Mail Removed)> wrote in message
news:8BF9026A-A92D-426F-877A-(E-Mail Removed)...
> Here's what you need.
>
> Sub AutoFilterSetToOff()
> If ActiveSheet.AutoFilterMode = True Then
> ActiveSheet.AutoFilterMode = False
> End If
> End Sub
>
> HTH
> --
> Data Hog
>
>
> "Munchkin" wrote:
>
>> Can you display the code? I don't know what it is & can't seem to be
>> able to
>> figure it out.
>>
>> "Rick Rothstein" wrote:
>>
>> > You can test the AutoFilterMode property of the worksheet... it will be
>> > True
>> > if the AutoFilter is active and False otherwise. You can set the
>> > property to
>> > False in your code to turn AutoFilter'ing off (but you cannot set the
>> > property to True to turn it back on though).
>> >
>> > --
>> > Rick (MVP - Excel)
>> >
>> >
>> > "Munchkin" <(E-Mail Removed)> wrote in message
>> > news:65530615-7598-4713-9A33-(E-Mail Removed)...
>> > >I can't figure out how to do this. Before my macro runs I want to
>> > >check to
>> > > see if AutoFilter is turned on. If it is I want to turn it off - if
>> > > it
>> > > isn't
>> > > then do nothing.
>> > >
>> > >
>> > >
>> > > Rows("2:4").Select
>> > > Selection.EntireRow.Hidden = False
>> > > Range("A2").Select
>> > > Selection.ClearContents
>> > >
>> > > Range("I2").Select
>> > > 'Application.Run "'NamedInsuredList 2
>> > > 11-2009.xls'!CheckBoxFilter_Click"
>> > > Range("PolicyList").Sort Key1:=Range("A7"), Order1:=xlAscending,
>> > > Header:= _
>> > > xlGuess, OrderCustom:=1, MatchCase:=False,
>> > > Orientation:=xlTopToBottom, _
>> > > DataOption1:=xlSortTextAsNumbers
>> > >
>> > > Range("A2").Select
>> >
>> > .
>> >


 
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
How do I turn on Auto Filter?? It is grayed out. =?Utf-8?B?UmF5?= Microsoft Excel Misc 4 18th Mar 2009 07:02 PM
Turn off a filter before running a macro Arno Microsoft Excel Programming 5 26th Sep 2008 09:46 AM
Macro to allow auto filter after running password protect Roady Microsoft Excel Misc 1 17th Jul 2008 06:34 PM
excel: how to turn auto-filter on? =?Utf-8?B?UGVkcm8gQ2VudGVubw==?= Microsoft Excel Worksheet Functions 0 31st Dec 2004 10:41 AM
Excel Auto Filter - cannot turn off. Kathleen Microsoft Excel Crashes 2 1st Oct 2004 09:12 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:42 PM.