Lock cell after data entry - Is it possible?

  • Thread starter Thread starter Kennyatwork
  • Start date Start date
K

Kennyatwork

Hello

I would like to make my spreadsheet tamperproof!

Various people are allowed to enter data into a sheet. I would like to stop
them going back and altering cells which have had data added. Is there code
which can lock a cell once data has been added to it?

TIA

Kenny
 
Kenny,

Here is some event code to do it.

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
On Error GoTo ws_exit
If Not Intersect(Target, Range("H10:J100")) Is Nothing Then
Me.Unprotect
Target.Locked = True
Me.Protect
End If
ws_exit:
Application.EnableEvents = True
End Sub

First, set all the cells on the sheet to unlocked (Cells>Protection), and
protectv the sheet (Tools>Protect), then this code should work for you.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
You could try something like:

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Application.UserName <> "Kennyatwork" Then
Application.Undo
End If
Application.EnableEvents = True
End Sub
 

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