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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Protect the sheet after setting the cell as unlocked.
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
If you still want help, please see post#4.
 
Upvote 0

Forum statistics

Threads
1,214,393
Messages
6,119,261
Members
448,880
Latest member
aveternik

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