How to un&protect certain sheets (NOT ALL SHEETS)

Zoticos

New Member
Joined
Jan 29, 2011
Messages
16
My macro below unprotects one sheet and locks or unlocks a range of cells then protects the sheet.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

I need help making my macro to do the same for 12 sheets out of the 85 sheets only.<o:p></o:p>

The name for the 12 sheets are “JAN”, “FEB”, ……… “DEC”. <o:p></o:p>

Was using the ARRAY command to select all 12 sheets (Sheets(Array("JAN", "FEB",………etc)).Select, but does not work to un&protect the sheets if all sheets are selected.<o:p></o:p>

So what I needs is something like, first to unprotect the 12 sheets then use the ARRAY command to select all 12 sheets and lock or unlock the cell range then protect the 12 sheets.<o:p></o:p>

I could use a loop to unprotect all sheets but I have 85 sheets in total which it does take a moment to run through a loop and I rather unprotect the 12 sheets only.<o:p></o:p>

Thank for any help users!<o:p></o:p>
<o:p></o:p>
<o:p>My Code:</o:p>
<o:p></o:p>
Sub Month_Lock()<o:p></o:p>
Dim lockstat As Range<o:p></o:p>
Dim Password<o:p></o:p>

'Set worksheet password<o:p></o:p>
Password = "bigben" 'set your password<o:p></o:p>
'Set lock status cell range<o:p></o:p>
Set lockstat = ActiveWorkbook.Sheets("SETUP").Range("F58")<o:p></o:p>
Set ThisSheet = ActiveSheet<o:p></o:p>
Application.ScreenUpdating = False<o:p></o:p>
<o:p></o:p>

'Check state of lock status<o:p></o:p>
If lockstat = True Then GoTo Unlock_Month:<o:p></o:p>
<o:p></o:p>
Sheets("JAN").Select<o:p></o:p>
Range("a1").Select <o:p></o:p>
ActiveSheet.Unprotect Password<o:p></o:p>
Range("F12:F14,G23:G25").Locked = True<o:p></o:p>
ActiveSheet.Protect Password<o:p></o:p>
ActiveSheet.EnableSelection = xlUnlockedCells<o:p></o:p>
Worksheets("SETUP").Range("B55").Value = 0<o:p></o:p>
ThisSheet.Select<o:p></o:p>
Set ThisSheet = Nothing<o:p></o:p>
Application.ScreenUpdating = True<o:p></o:p>
<o:p></o:p>
<o:p></o:p>Exit Sub<o:p></o:p>
<o:p></o:p>
Unlock_ Month:<o:p></o:p>
Sheets("JAN").Select 'this is added to reselect your sheet<o:p></o:p>
Range("a1").Select <o:p></o:p>
ActiveSheet.Unprotect Password<o:p></o:p>
Range("F12:F14,G23:G25").Locked = False<o:p></o:p>
ActiveSheet.Protect Password<o:p></o:p>
ActiveSheet.EnableSelection = xlUnlockedCells<o:p></o:p>
ThisSheet.Select<o:p></o:p>
Set ThisSheet = Nothing<o:p></o:p>
Application.ScreenUpdating = True<o:p></o:p>
Range("B55").Select<o:p></o:p>
Application.SendKeys "%{DOWN}", True<o:p></o:p>
<o:p></o:p>

End Sub<o:p></o:p>
 
Last edited:

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi Zoticos,

The code could be simplified to something like this....

Rich (BB code):
Sub Unlock_byMonth()
    Dim i As Long
    Dim strMonth As String, strPassword As String
 
    strPassword = "bigben" 'set your password
    Application.ScreenUpdating = False
    For i = 1 To 12
        strMonth = Format(WorksheetFunction.EoMonth(#12/31/2010#, i), "MMM")
        With Sheets(strMonth)
            .Unprotect strPassword
            .Range("F12:F14,G23:G25").Locked = True 
                 'add more steps.....
            .Protect strPassword
        End With
    Next i
End Sub

I didn't follow exactly how you are using Sheets("SETUP").Range("F58"). Hopefully you will be able to integrate that using the code with this concept:

For each Sheet representing the 12 months:
UnProtect
...Do something...
Protect
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,775
Members
452,942
Latest member
VijayNewtoExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top