VBA lock entire worksheet except for 1 cell

RWazoo

New Member
Joined
Oct 14, 2020
Messages
7
Office Version
  1. 2010
Platform
  1. Windows
At the end of the running of my VBA code, I want to protect the entire Worksheet except for cell A1.

At the beginning of the code I have:

Set WSInput = Worksheets("Input")
Set WSInputA1 = Worksheets("Input").Range("A1:A1")
WSInput.Unprotect

And at the end of the run I have:

WSInput.Protect
WSInputA1.Locked = False

The last line (WSInputA1.Locked = False) gets a Run-time error '1004': Unable to set the Locked property of the Range class
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
63,989
Office Version
  1. 365
Platform
  1. Windows
Protect the sheet after setting the cell as unlocked.
 

RWazoo

New Member
Joined
Oct 14, 2020
Messages
7
Office Version
  1. 2010
Platform
  1. Windows
Protect the sheet after setting the cell as unlocked.
Protecting the sheet after setting the cell as unlocked:
WSInputA1.Locked = False
WSInput.Protect

Got rid of my run-time error, but the entire sheet is then Protected - including cell A:1 which I want the user to have access to.
 

RWazoo

New Member
Joined
Oct 14, 2020
Messages
7
Office Version
  1. 2010
Platform
  1. Windows
After working on this problem for a couple of days, I have found that Excel macros can be fickled when it comes to this task.
I created another 'bare bones' spreadsheet that: .Unprotected the worksheet; .Locked certain cells; .Locked = False cell A1; and .Protected the worksheet, and the macro executes correctly.
The lines of code that do the securing of the spreadsheet/cells for the two macros are identical. But one works, and the other one does not.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
63,989
Office Version
  1. 365
Platform
  1. Windows
If you still want help, please see post#4.
 

Forum statistics

Threads
1,144,370
Messages
5,723,964
Members
422,529
Latest member
mbilal429

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
Top