Making cells readonly
Sarah
You have to Protect the sheet before locked cells become functional.
Sub lockdown()
With ActiveSheet
For i = 1 To 3
Sheet1.Columns(i).Locked = True
Next
.Protect DrawingObjects:=True, Contents:=True, _
Scenarios :=True
End With
End Sub
The default for Excel is that all cells are "locked" when protection is on.
You may want to "unlock" the other columns before locking up Columns 1 to 3.
Sub lockdown2()
Cells.Select
Selection.Locked = False
Columns("A:C").Locked = True
ActiveSheet.Protect DrawingObjects:=True, _
Contents:=True, Scenarios:=True
End Sub
Gord Dibben Excel MVP
On Sat, 7 Feb 2004 16:46:05 -0800, "Sarah"
wrote:
I have a spreadsheet that I am working with in VBA. I have tried making the sheet read only after populating it by using the following code:
For i = 1 to 3
sheet1.Columns(i).Locked = True
Next
However, I am still able to edit all cells. Is there some other syntax that I should use? Can't figure out why this won't work.
Thanks much.
|