If not IsError VBA problem

Sinbad

Board Regular
Joined
Apr 18, 2012
Messages
224
Hi all,

I´m trying to build in an error check for a simple macro that will clear all filters. For this I created a Userform, added some bottons, assigned the relevant Makros to them and Bob´s your Unlcle.

Works great bu then I noticed if I don´t have any filters set and click the "Clear Filter" button, it throws me an error.

So I´m trying to catch and test for the error and in the event that it happens, it should just jump to the end of the makro.

Makro used to be this

Code:
Sub RemFilter()
    ActiveSheet.ShowAllData
End Sub

Now I´m trying to cathc the error and thought this should work, but it doesnt :(

Code:
Sub RemFilter()
    If Not IsError(ActiveSheet.ShowAllData) Then
    ActiveSheet.ShowAllData
    Else
    End If
End Sub

Any suggestions ? The error code is 1004
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
IsError is a formula (used in Excel cells). Its not a vba function. Your simplest, and best, strategy is just to ignore the error:

Code:
Sub RemFilter()
    On Error Resume Next
    ActiveSheet.ShowAllData
End Sub

The VBA help file is a good place to start reading about Error Handling, by the way - that's what you are doing here.

ξ
 
Upvote 0
Try

Code:
Sub RemFilter()
    On Error Resume Next
    ActiveSheet.ShowAllData
    On Error GoTo 0
End Sub
 
Upvote 0
Hi Xenou, Thanks for a super fast reply.

Might find this interesting, I found a oneliner that does the job

Code:
    If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData
 
Upvote 0
Yes, that's good - don't need to worry about errors at all with that one.
ξ
 
Upvote 0

Forum statistics

Threads
1,223,641
Messages
6,173,506
Members
452,518
Latest member
SoerenB

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top