Hi There
I have a workbook with a number of tabs which I need to lock-down to prevent anyone from changing the data in the cells. They need to be able to interrogate the data using filters etc, but not change anything. Therefore I have password protected the cells using Review>Protect Sheet and ticked the relevant check boxes. Many people who use the spreadsheet leave filters applied all over the sheet, which is not helpful. Therefore, I have applied a macro to remove all filters on opening the spreadsheet (code below from another website). As I expected, this code works perfectly when the worksheets are unprotected, but doesn't work when they are. Can anyone advise what I can do so that I can lock all the cells in the worksheet AND have the macro work on open? Many thanks in advance.
I have a workbook with a number of tabs which I need to lock-down to prevent anyone from changing the data in the cells. They need to be able to interrogate the data using filters etc, but not change anything. Therefore I have password protected the cells using Review>Protect Sheet and ticked the relevant check boxes. Many people who use the spreadsheet leave filters applied all over the sheet, which is not helpful. Therefore, I have applied a macro to remove all filters on opening the spreadsheet (code below from another website). As I expected, this code works perfectly when the worksheets are unprotected, but doesn't work when they are. Can anyone advise what I can do so that I can lock all the cells in the worksheet AND have the macro work on open? Many thanks in advance.
VBA Code:
Sub auto_open()
'Updated by Extendoffice 20210625
Dim xAF As AutoFilter
Dim xFs As Filters
Dim xLos As ListObjects
Dim xLo As ListObject
Dim xRg As Range
Dim xWs As Worksheet
Dim xIntC, xF1, xF2, xCount As Integer
Application.ScreenUpdating = False
On Error Resume Next
For Each xWs In Application.Worksheets
xWs.ShowAllData
Set xLos = xWs.ListObjects
xCount = xLos.Count
For xF1 = 1 To xCount
Set xLo = xLos.Item(xF1)
Set xRg = xLo.Range
xIntC = xRg.Columns.Count
For xF2 = 1 To xIntC
xLo.Range.AutoFilter Field:=xF2
Next
Next
Next
Application.ScreenUpdating = True