what does method 'Unprotect" of object_Worksheet failed

ccafe8

New Member
Joined
Nov 1, 2008
Messages
43
I've got code that

is attached to a dropdown button,

it has a protect and unprotect line that looks like below:

-------------------

Private Sub combo_pl1_Change()
ActiveSheet.Unprotect ("password")
Select Case combo_pl1.Value

Case "Plus or Minus 0%"
Call non2020pl_rev0percent

Case "Plus or Minus 1000%"
Call non2020pl_rev1000percent

Case Else
MsgBox "Something Else"
End Select
ActiveSheet.Protect ("password")

End Sub


---------------------

can anyone tell me if there is somethign wrong or inefficient that is causing the error as mentioned when i save my work...
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi,

can anyone tell me if there is somethign wrong or inefficient that is causing the error as mentioned when i save my work...
I don't see why the combobox's change event would be raised when you save the workbook?

Instead of using activesheet, you can try using Me to make sure the correct sheet is being referenced:
Code:
Private Sub combo_pl1_Change()
    Me.Unprotect "password"
 
    Select Case combo_pl1.Value
 
        Case "Plus or Minus 0%"
            Call non2020pl_rev0percent
 
        Case "Plus or Minus 1000%"
            Call non2020pl_rev1000percent
 
        Case Else
            MsgBox "Something Else"
    End Select
 
    Me.Protect "password"
End Sub

Of course, make sure that "password" is the correct password for that sheet's protection.

Hope that helps...
 
Upvote 0

Forum statistics

Threads
1,202,984
Messages
6,052,914
Members
444,612
Latest member
FajnaAli

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