Selectively protect cell data

  • Thread starter Thread starter BaldOne
  • Start date Start date
B

BaldOne

I would like to , when a cell is empty, be able to enter data, but,
once data is entered have the cell protected. Is there any way to do
this. I'm a novice. thanks for any help.

Ken
 
Ken, here is one way,

Private Sub Worksheet_Change(ByVal Target As Range)
'******unlock all cells in the range first*********
Dim MyRange As Range
Const Password = "123" '**Change password here**
Set MyRange = Intersect(Range("A1:B10"), Target) '**change range
here**
If Not MyRange Is Nothing Then
Unprotect Password:=Password
MyRange.Locked = True
Protect Password:=Password
End If
End Sub

To put in this macro right click on the worksheet tab and view code, in the
window that opens paste this code, press Alt and Q to close this window and
go back to your workbook. If you are using excel 2000 or newer you may have
to change the macro security settings to get the macro to run. To change the
security settings go to tools, macro, security, security level and set it to
medium



--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003
 
Back
Top