Removing filters and hidden columns VBA

Affy99

New Member
Joined
Feb 2, 2016
Messages
10
Hi All,

I have a workbook which has circa 30 tabs and is accessed byapproximately 25 users simultaneously.

I’m looking for come coding to remove any current filters and unhideany columns then re-protect each sheet on opening.

I have the following code which is removing the filters but doesn’t unhidethe columns and isn’t allowing the filter to be re-applied once the sheet isprotected:

Sub Auto_Open()
Dim xWs As Worksheet
For Each Wks InThisWorkbook.Worksheets
On Error Resume Next
If Wks.AutoFilterMode Then
Wks.AutoFilterMode =False
AllowFiltering = True
userinterfaceonly = True
End If
Next Wks
End Sub


Any help would be greatly appreciated.

Affy
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Affy,

You might consider the following...

Code:
Sub Auto_Open()
Dim ws As Worksheet
On Error GoTo errHandler
For Each ws In ThisWorkbook.Worksheets
    With ws
        .Unprotect
        .Columns.Hidden = False
        If .AutoFilterMode = True Then .AutoFilterMode = False
        .Range("A1").AutoFilter
        .Rows(1).Locked = False
        .Protect AllowFiltering:=True, UserInterfaceOnly:=True
    End With
Next ws
errHandler:
    If Err.Number > 0 Then MsgBox "Sorry, an error occurred on Sheet " & ws.Name & vbCrLf _
    & Err.Number & " " & Err.Description
End Sub

In my quick research and simple testing, it seems the AllowFiltering property allows you to use an existing filter, not actually create one. The code places an autofilter into row 1.

The "On Error Resume Next" error checking has the potential to be dangerous in that it allows any error - code or content related - to be ignored without any warning to the user. It also makes it difficult to debug the code if it's on during testing.

Cheers,

tonyyy
 
Upvote 0
Hi Tonyyy,

Thank you very much for your reply. I will have a try with the code but I agree it may be dangerous to allow any error to be ignored.

Best Regards,

Affy
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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