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

  • Thread starter Thread starter RoBear!
  • Start date Start date
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
 
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
 
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
 
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
 
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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top