VBA Debug Error message box

mamady

Board Regular
Joined
Sep 23, 2011
Messages
238
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have the following code to clear out filters of a selected range, which works fine after assigning it to a button. However, if the button is clicked again I get a debug error. How can I disable that?

VBA Code:
Sub ClearFilter()

' ClearFilter Macro

Application.ScreenUpdating = False
    Rows("2:2").Select
    ActiveSheet.ShowAllData
    Range("A1").Select
Application.ScreenUpdating = True

End Sub


Thank you in advance
 
Last edited by a moderator:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try this
VBA Code:
Sub ClearFilter()
On Error Resume Next
   ActiveSheet.ShowAllData
On Error GoTo 0
   Range("A1").Select
End Sub
 
Upvote 0
Solution
Try this
VBA Code:
Sub ClearFilter()
On Error Resume Next
   ActiveSheet.ShowAllData
On Error GoTo 0
   Range("A1").Select
End Sub

Works like a charm :)

thank you very much, you are a star
 
Upvote 0
@mamady - Glad to hear your problem is solved.

I changed the marked solution post in this question. Next time, please mark the post that answered your question (post #2 in this case) instead of your final post. This way, it will help future readers to find the solution quickly.
 
Upvote 0
@mamady - Glad to hear your problem is solved.

I changed the marked solution post in this question. Next time, please mark the post that answered your question (post #2 in this case) instead of your final post. This way, it will help future readers to find the solution quickly.
noted, thank you
 
Upvote 0

Forum statistics

Threads
1,223,999
Messages
6,175,887
Members
452,679
Latest member
darryl47nopra

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