davidlocke83
New Member
- Joined
- May 9, 2022
- Messages
- 4
- Office Version
- 365
- Platform
- Windows
I'm attempting to protect the entire worksheet except for a set range for a series of worksheets that are identical. The workbook is comprised of time surveys for a number of cost centers. Each time survey is identical. However, I do not want them overriding some items and I don't want them to be able to view some hidden columns. Step 1 was using a Protect VBA, which works fine. I've run into problems with the unprotecting just the range.
I will start by saying I'm extremely green at VBA and I have piecemealed the below together using several forums. While I've been getting several errors, the last one is an "Error 91: Object Error Not Set" at the "Set Input Range = ws.Range ("A40:AT350")".
Sub UnProtectRangeInAllWorksheets()
Dim ws As Worksheet
Dim Pwd As String
Dim InputRange As Range
Set InputRange = ws.Range("A40:AT350")
Pwd = InputBox("Enter your password to unprotect all worksheets", "Unprotect Worksheets")
On Error Resume Next
For Each ws In Worksheets
If InputRange.Locked = True Then
ws.Unprotect Password:=Pwd
End If
If Err <> 0 Then
MsgBox "You have entered an incorect password. All worksheets could not " & _
"be unprotected.", vbCritical, "Incorect Password"
End If
On Error GoTo 0
Next ws
End Sub
I will start by saying I'm extremely green at VBA and I have piecemealed the below together using several forums. While I've been getting several errors, the last one is an "Error 91: Object Error Not Set" at the "Set Input Range = ws.Range ("A40:AT350")".
Sub UnProtectRangeInAllWorksheets()
Dim ws As Worksheet
Dim Pwd As String
Dim InputRange As Range
Set InputRange = ws.Range("A40:AT350")
Pwd = InputBox("Enter your password to unprotect all worksheets", "Unprotect Worksheets")
On Error Resume Next
For Each ws In Worksheets
If InputRange.Locked = True Then
ws.Unprotect Password:=Pwd
End If
If Err <> 0 Then
MsgBox "You have entered an incorect password. All worksheets could not " & _
"be unprotected.", vbCritical, "Incorect Password"
End If
On Error GoTo 0
Next ws
End Sub