MrExcel Publishing
Your One Stop for Excel Tips & Solutions


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:

for X = 1 to 7
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


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
Sheets(i).AutoFilter = True

The True part is simply left blank.

It is also possible to toggle a property with

someobject.someproperty = NOT someobject.someproperty


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

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

Re: Thanks...AUTOFILTER problem

The code worked perfectly. I really appreciate everyones input.