Need macro for protecting individual rows in a worksheet

G

Guest

I have a concept in my project i which I have make some rows of a worksheet
non-editable .i.e., read-only. I have tried many options but everything gave
me error. I can protect a complete worksheet but not individual rows. I would
like to know whether it is possible to protect certain rows of a worksheet &
if so, what is the function to use?
 
M

markwalling

if you look at an individual cell's properties, there is a locked
checkbox on the last page. that is set by default, locking the cell
when the sheet is protected. clearing that would allow the cell to be
edited on a protected sheet.

hope that gave you the insight you need.
 
C

Chip Pearson

By default, all cells are Locked, so when you protect the sheet,
all cells are protect. Click on the Select All button (the gray
box above the row numbers, to the left of the column letters), go
to the Edit menu, choose Cells, the protection tab, and uncheck
the Locked setting. Then, select the rows you want to protect, go
back to the Format dialog and check Locked. Finally, protect your
sheet.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
C

Chip Pearson

If you need this in VBA, use code like the following:

Sub AAA()
Cells.Locked = False
Rows(1).Locked = True
Rows(3).Locked = True
Rows(5).Locked = True
ActiveSheet.Protect
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
G

Guest

I tried it but I am getting the error "Unable to set the locked property of
the range class"
 
C

Chip Pearson

The sheet must not be protected when you run the code. Try this:

Sub AAA()
ActiveSheet.Unprotect
Cells.Locked = False
Rows(1).Locked = True
Rows(3).Locked = True
Rows(5).Locked = True
ActiveSheet.Protect
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

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

Top