Archive of Mr Excel Message Board

Back to Data in Excel archive index
Back to archive home

AUTOFILTER problem1
Posted by Brad on October 15, 2001 2:18 PM
I have a worksheet that I am trying to set to turn the AUTOFILTER on in CODE. So far I have:
I=7
for X = 1 to 7
sheet(I).select
With Selection
.AutoFilter.Range ("A1")
end with
I = I +1
next X
which works fine....EXCEPT.
It barfs when I have mixed sheets with Autofilter onoff in the workbook. Is there a way to check for IF on then ok ELSE AutoFilter = True end if? And set ALL of them ON or OFF accordingly?
(this if...then doesn't work.)
Any suggestions appreciated...TIA
Brad

Re: AUTOFILTER problem1
Posted by Jonathan on October 15, 2001 3:05 PM
I haven't worked with AutoFilter in particular, but the general way to code a property as you seem to want is (this is off the top if my head, so tell if it works for you (i.e. it's untested)):
If Sheets(i).AutoFilter Then
Else
Sheets(i).AutoFilter = True
EndIf
The True part is simply left blank.
It is also possible to toggle a property with
someobject.someproperty = NOT someobject.someproperty
HTH

Re: AUTOFILTER problem1
Posted by Gyula Lorant on October 16, 2001 1:00 AM
Dim x As Integer
For x = 7 To 14
If Sheets(x).AutoFilterMode = False Then Sheets(x).Range("A1").AutoFilter
Next

Re: Thanks...AUTOFILTER problem
Posted by Brad on October 16, 2001 4:49 AM
Thanks...
The code worked perfectly. I really appreciate everyones input.
Brad

This archive is from the original message board at www.MrExcel.com.
All contents © 1998-2004 MrExcel.com.
Visit our
online store to buy searchable CD's with thousands of VBA and Excel answers.
Microsoft Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.