Hello experts
I need your expertise to find the fault in the code and solution to correct this. I have this workbook where the data is pasted in one sheet ”Original” from column A to J whose cells are not locked and not hidden. The rest of the sheet is protected with a password and the cells are hidden and locked. The macro button is in column K. Other than this sheet there are several other sheets which are protected and hidden. When I run the code, the code should unprotect and unhide all the protected and hidden sheets in the workbook. When the macro ends, I want the code to again protect and hide all the other sheets which were already hidden. The columns A:J in Original sheet must stay unlocked and unhidden at all times.
Code
Option Explicit
Sub HideSheets()
Dim ws As Worksheet
ThisWorkbook.Unprotect Password:=123
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Original" Then
ws.Protect Password:=123
ws.Visible = xlSheetVeryHidden
Else
ws.Cells.Locked = True
ws.Range("A1:J" & Rows.Count).Locked = False
ws.Range("K:XFD").EntireColumn.Hidden = True
ws.Protect Password:=123
End If
Next ws
ThisWorkbook.Protect Password:=123
End Sub
Sub UnHideSheets()
Dim ws As Worksheet
ThisWorkbook.Unprotect Password:=123
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Original" Then
ws.Visible = xlSheetVisible
ws.Unprotect Password:=123
End If
Next ws
ThisWorkbook.Protect Password:=123
End Sub
Display More