View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
NickH NickH is offline
external usenet poster
 
Posts: 60
Default lock excel worksheet when loosing focus

Nader,

Not what you originally asked for but may be an acceptable 'simple'
solution for you...

PS : all this is to avoid to put in value by mistake in my excel sheet


Try putting the following procedure in your worksheet code module. It
will mean hitting Return twice for every legitimate entry but may be an
acceptable overhead to avoid an accidental entry...

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Response As Variant
Dim msg As String
Dim Title As String

msg = Target.Range("A1").Address & " = '" &
Target.Range("A1").Value & "'"
msg = msg & vbCrLf & vbCrLf
msg = msg & "Accept entry?"

Title = "Confirm Entry"

Response = MsgBox(msg, vbYesNo + vbQuestion, Title)

If Response = vbNo Then
With Application
.EnableEvents = False
.Undo
.EnableEvents = True
End With
End If
End Sub

Kind regards,
NickH