In a given worksheet, is it possible to create a macro that detects the presence of any active autofilter (in a range of columns, for example from column1 to 10) and remove them?
thanks.:)
In a given worksheet, is it possible to create a macro that detects the presence of any active autofilter (in a range of columns, for example from column1 to 10) and remove them?
thanks.:)
Hi Balangan,
Sub RemoveFilter()
If ActiveSheet.AutoFilterMode = True Then ActiveSheet.AutoFilterMode = False
End Sub
Will remove the autofilter if it is active
Regards,
Bill
I think it's the whole sheet or nothing. Use this line.
If ActiveSheet.AutoFilterMode Then ActiveSheet.Cells.AutoFilter
sorry i think i explained myself badly. I would like to remove only the value of any autofilter, not the existance of the autofilter itself.
If, for example, autofilter is active and column "B" contains names and has an active filter on name "Mario", i would like the macro to remove it.
thanks guys
Hi Balangan,
Sub removenames()
If ActiveSheet.AutoFilterMode = True Then
Sheet1.Range("B2:B20").SpecialCells(xlCellTypeVisible).ClearContents
End If
End Sub
I think this is maybe what you are after.
Regards,
Bill
Hi Balangan,
On reading your post again, my last post is probably not much help to you.
Regards,
Bill
Hi Balangan,
If you mean to delete all of the information for the filtered range, then change the line to:
Sheet1.range("A2:J1000").SpecialCells(xlCellTypeVisible).ClearContents
If you have more than 1000 rows, then change the number. This will clear all of the filtered records in the columns A to J
Regards,
Bill
Or if you just want all of the filters set to All
If ActiveSheet.AutoFilterMode Then ActiveSheet.ShowAllData
Hi Bill, thank you very much for your help. I will now try your solutions thanks you Derry also
Re: VBA : Detect and remove autofilter?
Just out of Interest ... if the autofilter is over a large number of rows releasing the autofilter can take more than a few seconds of processing time ... yet if you select the drop down tab of the column being filtered it is almost instant .... my question is How come?.
Re: VBA : Detect and remove autofilter?
Hi RedTussock,
Welcome to OzGrid.
Unfortunately the practice of "hijacking" a thread is not permitted, as per rule 8 of the rules you've agreed to:
"Never post a question in the Thread of another member. You MUST ALWAYS start you own New Thread"
As such I have closed this thread. Post a new thread with a link back to this one if you think it will help provide a solution.
Regards,
Robert
Don’t have an account yet? Register yourself now and be a part of our community!