Spin control on protected sheet

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,834
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have an ActiveX spin control on my worksheet which is linked to cell A1.

When I click on the spin control, cell A1 changes value.

If the worksheet is protected and I add this code:

Code:
Private Sub SpinButton1_Change()

    Me.Unprotect

End Sub

cell A1 still changes value, as expected.

However, if this code was added instead:

Code:
Private Sub SpinButton1_Change()

    Me.Unprotect
    Me.Protect
End Sub

it fails.

Why is that?

I would've thought the code would kick in, unprotect the sheet then protect it again. Stepping into the code works.
 

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.
It is by Excel's design and the OS's. After all, nothing happens simultaneously but always in a certain order.
In this case btw, the order in which it all happens doesn't have any effect on the result.
Starting with a protected sheet, compare these two scenarios:
Scenario 1:
1. update attempt;
2. unprotect by macro code;
3. protect by macro code.
Scenario 2:
1. unprotect by macro code;
2. protect by macro code.
3. update attempt;

Updating (the value of) the linked cell before running your second macro or afterwards makes no difference, the update attempt will fail due to a protected sheet.
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

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