Stopping error from showing VBA

oliviar

Board Regular
Joined
Sep 12, 2010
Messages
184
Hi Excelperts
I have a little macro to clear the autofilter on my page. But if the filter is ALREADY clear, it gives me an error. I have to get it to just do nothing if its already clear to stop this error from popping up (as its going to be distributed to others)

This is my code:
Code:
Sub clearfilter()
Sheets("data connection").Select
    Rows("1:1").Select
    ActiveSheet.ShowAllData
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try
Code:
Sub clearfilter()
Sheets("data connection").ShowAllData
End Sub
 
Upvote 0
I think you only want to only show all records if your dataset is currently filtered?? If so, try this:

Code:
Sub clearfilter()

    With Sheets("data connection")
        If .FilterMode = True Then
            .ShowAllData
        End If
    End With
        
End Sub

HTH

Robert
 
Upvote 0
Hello

Try this it will toggle Autofilter on and off.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> clearfilter()<br>  Sheets("data connection").Rows("1:1").AutoFilter<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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