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.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,944
Messages
5,856,446
Members
431,814
Latest member
Oriel Tzvi Shaer

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