Macro to define "Edit Ranges" password on multiple worksheets in workbook

Caitlin535

New Member
Joined
Jan 8, 2016
Messages
21
Hello! I have a workbook with multiple nearly-identical worksheets; each one is a timesheet for two-week periods. I need the same range of cells on every worksheet to be defined under "Allow Edit Ranges" and set with a password in order to edit those ranges. I can use the same password for every sheet - so again, it's the same range of cells in every sheet and same password. I'm hoping for a macro that would allow me to set up the "Edit Ranges" on all the worksheets at once, rather than having to do each one separately. I have a very similar macro that I use to protect and unprotect all the worksheets with a single macro - is the same possible for the "Edit Ranges" function?

For reference - the range I want to define as edit-able with a password is:
$C$3:$F$16,$M$3:$N$16

And the password can be:
6007

Any help would be much appreciated!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Sub EditRange()
Dim Sh As Worksheet
Dim Rng As Range
Dim i As Integer
Set Sh = Application.ActiveSheet
On Error Resume Next
' Unprotect worksheet.
Sh.Unprotect
Set Rng = Sh.Range("$C$3:$F$16", "$M$3:$N$16")
' Delete all current protection ranges

'MsgBox ws.Protection.AllowEditRanges.Count

For i = 1 To Sh.Protection.AllowEditRanges.Count
Sh.Protection.AllowEditRanges(i).Delete

Next


' Establish a range that can allow edits
' on the protected worksheet.
Sh.Protection.AllowEditRanges.Add Title:="Classified", Range:=Rng, Password:="6007"
Sh.Protect
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,984
Messages
6,122,601
Members
449,089
Latest member
Motoracer88

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