Excel Macro: Pause & ask user: "Are you sure you want to continue?

R

RoBear!

I have a Macro button that clears all input fields.
To avoid mistakenly clearing the fields, I want to insert a line in the
Macro that will generate a pop-up question: "Are you sure?" with a Yes/No
option.

I am new to Macros, and no nothing about VB.

Thanks,

Rob
 
M

Mike

Place this at the top of you macro
If MsgBox("Are you sure?", vbQuestion + vbyesCancel) <> vbYes Then
'Do nothing user has select no get out
Exit Sub
End If
 
F

FSt1

hi
best way may be to use an input box. something like this
If Inputbox("are you sure?!?!") = vbyes then
your delete macro
else
exit sub
end if.
you really didn't give enough info to give a real specific answer but play
with this. post back if you have problems.

Regards
FSt1
 
F

FSt1

hi again
correction. that sould be message box.
If msgbox("are you sure?!?!",vbyesno) = vbyes then
your delete macro
else
exit sub
end if.
an input box requires input by the user and here
 
R

RoBear!

Mike -- Thanks for your reply!
Problem: Yours works, but it only comes up with the question, "Are you
sure?" and if I click "Yes" it exits the macro, & if I click the "X" (upper
right) to exit, it also exits the macro -- seems to be no way to tell it to
execute the macro?

I think I need a "Yes" or "Cancel" option?

Thanks again for your help!

Rob
 
R

RoBear!

FSt1:
Thanks for your reply!

I tried to use your approach, but kept getting error msgs.

Here's a simplified version of my Macro (actual version just clears more
cells):

'
Range("B36:B38").Select
Selection.ClearContents
End Sub

How should it look after you edit?

Thanks again for your help!

Rob
 
R

RoBear!

Bingo! Since sendig you that last msg., I went to "MsgBox" Help and tried
the following:

If MsgBox("Are you sure?", vbOKCancel) <> vbOK Then

Works like a charm!

Thanks again!

Rob
 
Top