lock cell

  • Thread starter Thread starter ps
  • Start date Start date
P

ps

Hello,
I want to have a user enter data in a cell and as soon as he hits enter it
can not be changed. so, if he types the number 75 in cell a3 then hits
enter he can not go back and change it. any suggestions?
thanks!
Peri
 
One way would be to use a worksheet change event to lock the cell and
protect the sheet after the update has taken place. Right click the
sheet tab, select view code and paste the following event code in there:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$3" _
And Target.Value <> Empty Then
Me.Cells.Locked = False
Target.Locked = True
Me.Protect Password:="thepassword"
End If
End Sub

Hope this helps
Rowan
 
That worked great, thanks. I was trying to extend it to a bigger range like
all of column and and column c....would you mind explaining how to do
that...
thanks again!
 
Start out with the sheet unprotected. Select all the cells that you want
users to be able to enter data into and use the Format>Cells>Protection
menu option to uncheck the locked checkbox. Then use
Tools>Protection>Protect Sheet to apply protection to the sheet. You can
choose to use a password or leave it blank. Then change the event as
follows (I have assumed you meant column A and Column C):

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count = 1 And (Target.Column = 1 _
Or Target.Column = 3) Then
Me.Unprotect Password:="thepassword"
Target.Locked = True
Me.Protect Password:="thepassword"
End If
End Sub

Regards
Rowan
 

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