protect cells but allow to enter data but not remove once entered

H

hugrl

set up spreadsheet for holidays but need to protect cells but allow a user to
enter a number in a cell but not allow to remove once entered
 
D

Dave Peterson

This sounds like a bad idea to me. How would you ever correct typing mistakes?
 
G

Gord Dibben

This sheet event code will lock cells in columns B and C and enter the login
username in column C when data is entered in column B

Note: first unlock all cells in columns B and C

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"
If Target.Value <> "" Then
Target.Locked = True
With Target.Offset(0, 1)
.Value = Environ("Username")
.Locked = True
End With
End If
End If
enditall:
Application.EnableEvents = True
ActiveSheet.Protect Password:="justme"
End Sub

To hide the code and password from prying eyes, lock the VBA Project from
viewing.


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