I have a worksheet I want to keep unprotected but still prevent data in locked cells from being deleted. I tried using a Worksheet_Change event but can’t get it to work. Your help would be much appreciated.
When a range of cells is selected (cells could be a mixture of locked and unlocked), and the Delete key is pressed, I want the macro to delete only the data in unlocked cells.
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Selection, Columns("A:G")) Is Nothing Then
Dim rng As Range, cell As Range
Set rng = Selection
For Each cell In rng
If cell.Locked = True Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
Next cell
End If
End Sub
When a range of cells is selected (cells could be a mixture of locked and unlocked), and the Delete key is pressed, I want the macro to delete only the data in unlocked cells.
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Selection, Columns("A:G")) Is Nothing Then
Dim rng As Range, cell As Range
Set rng = Selection
For Each cell In rng
If cell.Locked = True Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
Next cell
End If
End Sub