Exit / disable edit mode after double click handled event

[Originally posted by]: http://stackoverflow.com/questions/8848253/exit-disable-edit-mode-after-double-click-handled-event

You have to cancel the action with the variable given in argument:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
     MsgBox "a cell was clicked!", vbOKOnly, "a click"
     'Disable standard behavior     
     Cancel = True
End Sub

Here is a dummy example:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim response As Variant
    response = MsgBox("Are you sure you want to edit the cell?", vbYesNo, "Check")
    If response = vbYes Then
        Cancel = False
    Else
        Cancel = True
    End If
End Sub

Note that you wouldn’t have to set Cancel to False because it the default value (this is for the example purpose).

shareedit
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s