MrExcel Publishing
Your One Stop for Excel Tips & Solutions

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


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

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


Posted by Brad on October 16, 2001 4:49 AM

Re: Thanks...AUTOFILTER problem

Thanks...
The code worked perfectly. I really appreciate everyones input.

Brad