ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   AutoFilter toggling in VBA (How to use correctly) (https://www.excelbanter.com/excel-discussion-misc-queries/32474-autofilter-toggling-vba-how-use-correctly.html)

Dennis

AutoFilter toggling in VBA (How to use correctly)
 
XL 2003

In VBA I calculate a range (myRange) to apply in an autofilter.

I have used both of the following code and the AutoFilter toggles on to off
each time I run the code. My goal is to have the VBA code remove all
previous settings then apply
AutoFilter to myRange. Therefore I tried to clear settings:

Selection.AutoFilter -or- ActiveSheet.UsedRange.AutoFilter

Later in the same procedure I used:

If myRange.AutoFilter Then myRange.AutoFilter

-or-

myRange.AutoFilter

No matter what my approach, the AutoFilter toggles on to off
each time I run the procedure.

Where is my logic breaking down?

Dennis

Norman Jones

Hi Dennis,

Try something like:

Sub Tester()
With ActiveSheet
If .AutoFilterMode Then
If .FilterMode Then .ShowAllData
Else
.Range("A1").AutoFilter
End If
End With
End Sub

---
Regards,
Norman



"Dennis" wrote in message
...
XL 2003

In VBA I calculate a range (myRange) to apply in an autofilter.

I have used both of the following code and the AutoFilter toggles on to
off
each time I run the code. My goal is to have the VBA code remove all
previous settings then apply
AutoFilter to myRange. Therefore I tried to clear settings:

Selection.AutoFilter -or- ActiveSheet.UsedRange.AutoFilter

Later in the same procedure I used:

If myRange.AutoFilter Then myRange.AutoFilter

-or-

myRange.AutoFilter

No matter what my approach, the AutoFilter toggles on to off
each time I run the procedure.

Where is my logic breaking down?

Dennis





All times are GMT +1. The time now is 07:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com