PDA

View Full Version : Amend VBA Code to include extra worksheet(s)



Pete
08-14-2008, 04:11 AM
See attached snippet
Hi Experts

Need to modify the VBA Code as shown below so that all current worksheet are unprotected and password protected using the current password.....

BUT the following two worksheet are unprotected and password protected using a different password.

So for the worksheet(s) "shtLTD", "shtPricing"

i want to change the vba code so that

sht.Unprotect Password:=Sheet11.Range("C2").value also includes

sht.Unprotect Password:=includes =sheet11.Range("D2").value = "shtLTD"
sht.Unprotect Password:=includes =sheet11.Range("D3").value = "shtPricing

Pete
08-14-2008, 04:20 AM
Sub ProtectSheets()
Dim sht As Variant

For Each sht In ActiveWorkbook.Sheets
Select Case sht.CodeName
Case "Sheet1"
sht.Protect Password:=Sheet11.Range("C2").value

Case "Sheet2", "Sheet3", "Sheet4", "Sheet5", "Sheet6", "Sheet7", "Sheet8", "Sheet9", _
"Sheet12", "Sheet13", "Sheet15", "Sheet16", "Sheet17", "Sheet18", _
"Sheet25", "shtSellIn", "shtArchive"
sht.Protect Password:=Sheet11.Range("C2").value, AllowFormattingColumns:=True, AllowFormattingRows:=True
End Select
Next sht
End Sub
Edited by Aussiebear

Pete, if you want to post a section or sections of code, please use the VBA button. This makes the code so much easier to read than this

Dim sht As Variant

For Each sht In ActiveWorkbook.Sheets
Select Case sht.CodeName
Case "Sheet1"
sht.Protect Password:=Sheet11.Range("C2").value

Case "Sheet2", "Sheet3", "Sheet4", "Sheet5", "Sheet6", "Sheet7", "Sheet8", "Sheet9", _
"Sheet12", "Sheet13", "Sheet15", "Sheet16", "Sheet17", "Sheet18", _
"Sheet25", "shtSellIn", "shtArchive"
sht.Protect Password:=Sheet11.Range("C2").value, AllowFormattingColumns:=True, AllowFormattingRows:=True
End Select
Next sht
End Sub