Lock a Cell or Row

  • Thread starter Thread starter afmullane
  • Start date Start date
A

afmullane

Hi Guys,

I want to lock a cell or row so that the user of the spreadseet won't
be able to edit the contents of the cell or row.

Any help would be greatly appreciated,

Aidan
 
select the cells/rows/ranges

format=>Cells=>Protection Tab, click Locked

then
Tools=>Protect sheet
 
I should add that all cells by default are Locked. this is not applied
until the sheet is protected - so in practicality, you need to select the
cells you want the user to have access to and do

format=>Cells=>Protection tab and click unlocked. Then protect the sheet.
 
Hi Tom,

Thanks for your help Tom but do you know of a way of locking a cel
from the user but that the cell can still be manipulated through VB
code??

Aida
 
One way is to just have your code unprotect the sheet, do its changes and
reprotect the sheet.

with worksheets("sheet99")
.unprotect password:="hithere"
'do the work
.protect password:="hithere"
end with

An alternative is to protect the sheet in code.

Option Explicit
Sub auto_open()
With Worksheets("sheet99")
.Protect Password:="hithere", userinterfaceonly:=True
End With
End Sub

It needs to be reset each time you open the workbook. (excel doesn't remember
it after closing the workbook.)

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

There are a few things that your macro won't be able to do--so test your code
before you distribute the workbook.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top