Object defined error while sheet protected but no error when not protected

ColinCoady

New Member
Joined
Mar 21, 2019
Messages
35
Not sure why this is happening. The following code works fine when sheet is Unprotected but gives a Run-time error '1004' Application-defined or object-defined error when the sheet is protected. All the cells involved are unlocked. Can anyone figure out the issue & provide a solution? I don't want to leave the sheet unprotected.
Thanks
-Colin
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Address <> "$E$7" Then Exit Sub
  If Target <> "Other%" Then Target.Offset(0, 2).ClearContents
  If Target <> "Other%" Then Target.Offset(0, 2).Interior.ColorIndex = 0
  If Target = "Other%" Then Target.Offset(0, 2).Select
  If Target = "Other%" Then Target.Offset(0, 2).Interior.ColorIndex = 27
  End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Unprotect and re-protect sheet
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  
  If Target.Address <> "$E$7" Then Exit Sub
    [COLOR=#ff0000]Me.Unprotect ("password")[/COLOR]
        If Target <> "Other%" Then Target.Offset(0, 2).ClearContents
        If Target <> "Other%" Then Target.Offset(0, 2).Interior.ColorIndex = 0
        If Target = "Other%" Then Target.Offset(0, 2).Select
        If Target = "Other%" Then Target.Offset(0, 2).Interior.ColorIndex = 27
   [COLOR=#ff0000] Me.Protect ("password")[/COLOR]
  End Sub
 
Upvote 0
Thank you - that worked.
Guess I was looking for something more complicated
Never thought of an easy work around.
-Colin
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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