Quote Originally Posted by clif
When I run the macro in excel, there is a message box come out.
There is two options "Delete" and "Cancel". I always need to press the "Delete" button. What is the vba code for pressing the "Delete" button?
If you designed userform for confirm delete, you need to set property for command Delete (Default=true)

If use Msgbox, try this code:

Sub AskAndDo()
If MsgBox("Are you sure ?", vbYesNo + vbQuestion) = vbNo Then
   Exit Sub
Else
   'Code goes here
   
End If
End Sub