auto locking cells after new entry/edit

P

patbayns

Is it possible to set excel to automatically lock a cell after entering data
or after editing?
 
G

Gord Dibben

Yes

Using event code.

Assuming column B cells are unlocked and the sheet is protected with
password "justme", as you enter data in column B, the cell will become
locked.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error GoTo enditall
Application.EnableEvents = False
If Target.Cells.Column = 2 Then
ActiveSheet.Unprotect Password:="justme"
N = Target.Row
If Excel.Range("B" & N).Value <> "" Then
Excel.Range("B" & N).Locked = True
End If
End If
enditall:
ActiveSheet.Protect Password:="justme"
Application.EnableEvents = True
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code".

Copy/paste the code into that module.

I'm sure your needs are not exactly as per sample above.

If you provide more detail perhaps code could be tailored.


Gord Dibben MS Excel MVP
 

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