How do I lock and unlock cells?

AChimpNamedCornelius

Board Regular
Joined
Aug 22, 2002
Messages
91
application.Worksheets("MyWorksheet").Range("A1", "R7").Locked = True

seems to not bomb at least, but I can still edit the cells. I go to Tools->Protection and protect the sheet, but then all cells are uneditable, not just the ones I want.

How do I make things like column headers, etc. unchangeable while still allowing the editing of the other cells?

I need to do this via code at startup to take care of people unlocking them by accident. In a similar post, the one response suggested recording a macro, locking a cell, then checking out what the macro recorded. That did nothing for me as the macro record button is grayed out.
 

Some videos you may like

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Cells are locked by default, but the locking has no effect unless the sheet is protected.

So you need to unlock the cells you want the user to be able to edit then protect the sheet.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,514
Messages
5,602,093
Members
414,501
Latest member
mdhaumyu

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