PDA

View Full Version : Clearing my autofilter



percy4
04-21-2009, 12:34 AM
Hi VBA-lovers,

I’ve got a small problem with an autofilter reset.

Pls see below code. The problem I am having with this code is that it gives me the “runtime error 1004. Showall data method on worksheet class failed” when I press this button without any parameters in the autofilter is set. It works fine when a parameter is set.
It’s probably very easy but I am a total noob at VBA programming.

What I want is just to clear any possible filter parameters not deleting the autofilter itself.

Please help me =)

Regards
Per


Sub flooring_veiw()

Sheets("History sheet").Select
Columns("A:AA").Select
Selection.EntireColumn.Hidden = False
If ActiveSheet.AutoFilterMode Then ActiveSheet.ShowAllData
' rensar ditt gamla val
Sheets("History sheet").Select
Columns("J:U").Select
Selection.EntireColumn.Hidden = True
ActiveWindow.DisplayHorizontalScrollBar = False
Range("A1").Select
ActiveWindow.ScrollColumn = 1
End Sub

JONvdHeyden
04-21-2009, 01:18 AM
Hello

ShowAllData will work if the range is currently filtered (i.e. with criteria). It will not if it is already displaying all data. Therefore I think it's ok to skip the error:


On Error Resume Next '// proceed despite error //
ActiveSheet.ShowAllData '// checking autofiltermode is not necessary //
On Error GoTo 0 '// turn error handling back on //

Bob Phillips
04-21-2009, 02:06 AM
Sub flooring_veiw()

Sheets("History sheet").Select
Columns("A:AA").Hidden = False
If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData ' rensar ditt gamla val
Sheets("History sheet").Select
Columns("J:U").Hidden = True
ActiveWindow.DisplayHorizontalScrollBar = False
Range("A1").Select
ActiveWindow.ScrollColumn = 1
End Sub