anythinggoes3949
New Member
- Joined
- Feb 8, 2024
- Messages
- 3
- Office Version
- 2013
- Platform
- Windows
Hello, I've been writing fairly simple macros for a few years and can usually find what I need in the forums. This time though I'm completely stumped.
I have workbook containing multiple worksheets. This includes a a worksheet called "Master" which contains a list of a select few of the worksheet names found within the same workbook. I've set this list as a named range called "Worksheet_Names".
I would like the macro to loop through the list of worksheet names, open each worksheet in the list in turn and password protect these worksheets. I don't want to password protect every sheet in the workbook, only those listed within this range. If I can get this to work, then I'll set up another macro to unprotect the same sheets.
I'm finding the code gets stuck (debug error) at the 'Sheets(Range(" & cell & ").Value).Activate' line of code so I'm assuming I've done something wrong here. Any help would be greatly appreciated. This is the first time I've posted here so apologies if I've done anything wrong within my post.
Sub Protect_Sheets()
'
Sheets("Master").Activate
Dim cell As Range
For Each cell In ActiveSheet.Range("Worksheet_Names")
Sheets(Range(" & cell & ").Value).Activate
ActiveSheet.Protect "Password1234"
Next cell
End Sub
I have workbook containing multiple worksheets. This includes a a worksheet called "Master" which contains a list of a select few of the worksheet names found within the same workbook. I've set this list as a named range called "Worksheet_Names".
I would like the macro to loop through the list of worksheet names, open each worksheet in the list in turn and password protect these worksheets. I don't want to password protect every sheet in the workbook, only those listed within this range. If I can get this to work, then I'll set up another macro to unprotect the same sheets.
I'm finding the code gets stuck (debug error) at the 'Sheets(Range(" & cell & ").Value).Activate' line of code so I'm assuming I've done something wrong here. Any help would be greatly appreciated. This is the first time I've posted here so apologies if I've done anything wrong within my post.
Sub Protect_Sheets()
'
Sheets("Master").Activate
Dim cell As Range
For Each cell In ActiveSheet.Range("Worksheet_Names")
Sheets(Range(" & cell & ").Value).Activate
ActiveSheet.Protect "Password1234"
Next cell
End Sub