Macro debugs when not filtering

projectile

Board Regular
Joined
Dec 14, 2007
Messages
193
I have a worksheet "Latest Rates" which uses autofilter and so I have setup a macro to reset filtering when the exel sheet is opened and works fine; however if the sheet is opened and reset is not applicable i.e. no filter criteria saved from last time it was used, the macro crashes. below is the code I entered

Private Sub Workbook_Open()
Sheets("Latest Rates").Select
With ThisWorkbook.Worksheets("Latest Rates")
If .AutoFilterMode Then
.ShowAllData
End If
End With
End Sub

please advise
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
projectile,


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. And, paste the copied code into VBAProject, Microsoft Excel Objects, ThisWorkbook (on the right pane) by pressing the keys CTRL + V
5. Press the keys ALT + Q to exit the Editor, and return to Excel


Code:
Private Sub Workbook_Open()
Sheets("Latest Rates").Select
With ThisWorkbook.Worksheets("Latest Rates")
  If .FilterMode = True Then
    .ShowAllData
  End If
End With
End Sub


Save the workbook, close the workbook, then open the workbook.
 
Upvote 0

Forum statistics

Threads
1,223,710
Messages
6,174,017
Members
452,542
Latest member
Bricklin

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