Dropdown box protection

bloesch1

New Member
Joined
Aug 24, 2010
Messages
25
Hi, I have a protected worksheet that has a number of macros that work correctly which are similar in that they unprotect the sheet at the beginning and protects it when the macro has finished. However, I have a dropdown box that I'm attempting to apply the same logic to which isn't working correctly.

When I select a value from the dropdown list, I receive an error stating that the cell or chart I'm trying to change in protected and therefore read-only. Once I hit ok, the feature works fine and I'm able to select a value from the list and get the correct output. From the code below, can you see why I'm still receiving the initial error?

Thank you!

Sub DropDown133_Change()
Sheets("MainMap").Unprotect Password:="password"

Dim strMap As Integer

strMap = Range("I4").Value
Select Case strMap
Case 1
1
Case 2
2
Case 3
3
Case 4
4
Sheets("MainMap").protect Password:="password"
End Select


End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
I don't think it is the code. Is the control linked to a cell that is locked when protected? If so changing the protection formatting for that cell might fix things.
 
Upvote 0
Thanks for the quick response!

I've double-checked all the cells and objects and I set them all the unlocked for experimental purposes. However, I still get the initial error...
 
Upvote 0
ok, you can fix it I believe by turning notifications off.
Rich (BB code):
Sub DropDown133_Change()
Application.DisplayAlerts = False
Sheets("MainMap").Unprotect Password:="password"
 
Dim strMap As Integer
 
strMap = Range("I4").Value
Select Case strMap
Case 1
1
Case 2
2
Case 3
3
Case 4
4
Sheets("MainMap").protect Password:="password"
End Select
Application.DisplayAlerts = True
 
End Sub
<!-- / message -->
 
Last edited:
Upvote 0
One error I've made in my description of the situation is that it only seems to work (taking into account I have to hit "ok" when the error initially appears) is when the final code that adds the protection back IS NOT in the code. Sorry for the omission.
 
Upvote 0
Is this in a form?
I suggest moving the actual changing code to a module:
Leave this in your page/form/wherever.
Rich (BB code):
Sub DropDown133_Change()
Application.DisplayAlerts = False
InterpretChange()
Application.DisplayAlerts = True
End Sub
Put this in the module.
Rich (BB code):
Sub InterpretChange
Sheets("MainMap").Unprotect Password:="password"
 
Dim strMap As Integer
 
strMap = Range("I4").Value
Select Case strMap
Case 1
1
Case 2
2
Case 3
3
Case 4
4
End Select
Sheets("MainMap").protect Password:="password"
 
End Sub

Also, can you tell me more about where you have your code? Where is this dropdown? Is it a result of data validation or is it a button?
 
Upvote 0

Forum statistics

Threads
1,214,885
Messages
6,122,085
Members
449,064
Latest member
MattDRT

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