PDA

View Full Version : Solved: Autofilter



IrishCharm
10-01-2008, 03:52 AM
Hi,

Any ideas how i go in and automatically either remove all filters from tabs or add filters to all tabs in a workbook regardless of whether there are already existing filters or not?

Selection.autofilter either adds or removes a filter but does not distinguish between a filter already being there.

for example if i run a macro to autofilter a tab but someone else has left a filter already on it - my running selection.autofilter will remove the filter and leave none there.

Any idea how i can go through a workbook and
1: identift if there is a filter on the tab
2: on the back of this, then either add or remove existing filter.

I am completely stumped with this one sorry!!!

Sarah

Kenneth Hobs
10-01-2008, 05:18 AM
Sub CheckAutoFilters()
Dim lngSheet As Long
For lngSheet = 1 To Sheets.Count
Debug.Print Worksheets(lngSheet).Name, Worksheets(lngSheet).AutoFilterMode
Next lngSheet
End Sub

vzachin
10-01-2008, 09:01 AM
something like this works for me
If ActiveSheet.AutoFilterMode Then
ActiveSheet.AutoFilterMode = False
Else
ActiveSheet.Range("A3").AutoFilter
End If

IrishCharm
10-03-2008, 06:43 AM
That is just the answer thanks for that!!

Apologies for not getting back sooner.

Sarah




something like this works for me
If ActiveSheet.AutoFilterMode Then
ActiveSheet.AutoFilterMode = False
Else
ActiveSheet.Range("A3").AutoFilter
End If