View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Damon Longworth[_3_] Damon Longworth[_3_] is offline
external usenet poster
 
Posts: 23
Default Allowing entry only once

Have a look at Intersect in help. You could test if the Target address
intersects with your desired range, then do your tests for a first time edit.

"Adam" wrote:

I have the following code which prevents the user to edit the cell A1 more
than once

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Original As Variant
Dim NewVal As Variant
If Target.Count 1 Then Exit Sub
If Target.Address = "$A$1" Then
NewVal = Target.Value
Application.EnableEvents = False
Application.Undo
Original = Target.Value
If Original = "" Then
Target = NewVal
Else
MsgBox "No change to this cell is allowed"
End If
Application.EnableEvents = True
End If
End Sub

How do I edit this code to make it work for more than A1 i.e. A1:A100
Thanks
Adam