VBA - Show All Data

Foz1980

Board Regular
Joined
May 6, 2015
Messages
128
Hi all,

I am using the below code to show all data every time a specific workbook is opened, however if I protect the sheet and share it then it does not work.
When I've protected it I have ticked the box to allow the use of Auto-Filter but the code does not work.

Code:
Private Sub Workbook_Open()
    Dim sh As Variant
    For Each sh In Worksheets
      If sh.FilterMode Then sh.ShowAllData
    Next
End Sub

Can anyone help please?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Have the users enabled macros?

Alternatively you could try to clear all filters when the user closes the WB.
 
Upvote 0
Sorry, I should have been more specific with how it doesn't work.
All macros are enabled. But when opening the workbook, if a filter is present I get "Run-time error '1004'. ShowAllData method of Worksheet class failed".
 
Upvote 0
Have you tried the following?

Code:
Private Sub Workbook_Open()
    Dim sh As Variant
    For Each sh In Worksheets
      If sh.FilterMode Then sh.AutoFilter.ShowAllData
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,756
Messages
6,174,320
Members
452,555
Latest member
colc007

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