justanotheruser
Board Regular
- Joined
- Aug 14, 2010
- Messages
- 96
Hi all,
Because the following code will be used by multiple end users, I would like to be able to protect the entire workbook so they can't delete/move/show sheets they shouldn't be able to. However, for the code below to work and show/hide sheets, the workbook needs to be unprotected and then reprotected. Therefore, I recorded a macro to see what the code is, and it's relatively simple so I inserted it as below.
E4 is a drop down list, and "Select Entity" (without "") is the first default option in the drop down list. I can select any of the things in the drop down list and it will do its magic, but if I return to "Select Entity" - the first option in the drop down list the workbook is unprotected for some reason - probably because it is the first value of the cell. Any suggestions?
Thank you again! Today is question asking for me, hopefully next week will be helping! :D
Because the following code will be used by multiple end users, I would like to be able to protect the entire workbook so they can't delete/move/show sheets they shouldn't be able to. However, for the code below to work and show/hide sheets, the workbook needs to be unprotected and then reprotected. Therefore, I recorded a macro to see what the code is, and it's relatively simple so I inserted it as below.
E4 is a drop down list, and "Select Entity" (without "") is the first default option in the drop down list. I can select any of the things in the drop down list and it will do its magic, but if I return to "Select Entity" - the first option in the drop down list the workbook is unprotected for some reason - probably because it is the first value of the cell. Any suggestions?
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim LR As Long, i As Long
[COLOR="Red"]ActiveWorkbook.Unprotect[/COLOR]
If Target.Address(False, False) = "E4" Then
If Target.Value = "Select Entity" Then
For i = 1 To Worksheets.Count
If Sheets(i).Name <> "Title" Then Sheets(i).Visible = False
Next i
Exit Sub
End If
Application.ScreenUpdating = False
For i = 1 To Worksheets.Count
If Sheets(i).Name <> "Title" Then Sheets(i).Visible = False
Next i
With Sheets("Mapping")
LR = .Range("C" & Rows.Count).End(xlUp).Row
For i = 3 To LR
If Target.Value = .Range("C" & i).Value And .Range("D" & i).Value <> "" Then Sheets(.Range("D" & i).Value).Visible = True
Next i
End With
Application.ScreenUpdating = True
' Used to show non-BU sheets for all entities, no matter of choice from dropdown box. Set all non-BU sheets to true to show them.
Sheets("Other").Visible = True
Sheets("BL_PS").Visible = True
End If
[COLOR="red"]ActiveWorkbook.Protect Structure:=True, Windows:=False[/COLOR]
End Sub
Thank you again! Today is question asking for me, hopefully next week will be helping! :D