Running a Macro with a Protected Sheet

excellingatmyjob

New Member
Joined
Aug 19, 2014
Messages
4
Hello,

I have a macro running to hide/unhide certain columns depending on a user's selection in the drop down menu(s). I then unlocked the drop-down menu cells and protected the sheet. When I do so, the following error shows up:

Run-time error '1004":
Unable to set the Hidden property of the Range class

I'm pretty sure this error comes up because the sheet is protected, but how can I make it so the user can select ONLY the drop-down menu cells, yet the macro will still run? Below is my current code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("E29") = "*None" Then
Rows("30:31").EntireRow.Hidden = True
Rows("33").EntireRow.Hidden = False
ElseIf Range("E29") = "Perimeter Handrails Only" Then
Rows("33").EntireRow.Hidden = True
Rows("30:31").EntireRow.Hidden = False
ElseIf Range("E29") = "Flush Platform one Face" Then
Rows("33").EntireRow.Hidden = True
Rows("30:31").EntireRow.Hidden = False
ElseIf Range("E29") = "Offset Platform one Face" Then
Rows("33").EntireRow.Hidden = True
Rows("30:31").EntireRow.Hidden = False
ElseIf Range("E29") = "Other" Then
Rows("33").EntireRow.Hidden = True
Rows("30:31").EntireRow.Hidden = False
End If
End Sub

Any assistance will be greatly appreciated!
Thank you.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Try it like this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("E29") = "*None" Then
[B][COLOR=#ff0000]ActiveSheet.Unprotect
[/COLOR][/B]Rows("30:31").EntireRow.Hidden = True
Rows("33").EntireRow.Hidden = False
ElseIf Range("E29") = "Perimeter Handrails Only" Then
Rows("33").EntireRow.Hidden = True
Rows("30:31").EntireRow.Hidden = False
ElseIf Range("E29") = "Flush Platform one Face" Then
Rows("33").EntireRow.Hidden = True
Rows("30:31").EntireRow.Hidden = False
ElseIf Range("E29") = "Offset Platform one Face" Then
Rows("33").EntireRow.Hidden = True
Rows("30:31").EntireRow.Hidden = False
ElseIf Range("E29") = "Other" Then
Rows("33").EntireRow.Hidden = True
Rows("30:31").EntireRow.Hidden = False
End If
[B][COLOR=#ff0000]ActiveSheet.Protect
[/COLOR][/B]End Sub
 
Upvote 0
That prompts me to enter in the password...

The users will not have the password because I do not want them to edit other cells. Anyway to do this without a password prompt?
 
Upvote 0
Just put your password in the red areas in the amended code below:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("E29") = "*None" Then
ActiveSheet.Unprotect Password:="[B][COLOR=#ff0000]here[/COLOR][/B]"
Rows("30:31").EntireRow.Hidden = True
Rows("33").EntireRow.Hidden = False
ElseIf Range("E29") = "Perimeter Handrails Only" Then
Rows("33").EntireRow.Hidden = True
Rows("30:31").EntireRow.Hidden = False
ElseIf Range("E29") = "Flush Platform one Face" Then
Rows("33").EntireRow.Hidden = True
Rows("30:31").EntireRow.Hidden = False
ElseIf Range("E29") = "Offset Platform one Face" Then
Rows("33").EntireRow.Hidden = True
Rows("30:31").EntireRow.Hidden = False
ElseIf Range("E29") = "Other" Then
Rows("33").EntireRow.Hidden = True
Rows("30:31").EntireRow.Hidden = False
End If
ActiveSheet.Protect Password:="[B][COLOR=#ff0000]here[/COLOR][/B]"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,866
Messages
6,121,996
Members
449,060
Latest member
mtsheetz

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