Msg Box in IF statement?

E

Elise148

How would I go about putting a Msg Box in an IF statement in VBA???

For example, I would want to say, if something is clicked in another message
box, proceed with the macro, if something else is clicked, stop the macro?????
 
T

Toppers

On a MsgBox you can set the YES,NO,CANCEL buttons in msgbox parameters...

resp=Msgbox(........,VbYESNO)

IF resp=vbYES then

IF resp=VbNO then

HTH
 
E

Elise148

Thanks! I'll give that a try!


Toppers said:
On a MsgBox you can set the YES,NO,CANCEL buttons in msgbox parameters...

resp=Msgbox(........,VbYESNO)

IF resp=vbYES then

IF resp=VbNO then

HTH
 
E

Elise148

What if I want to run the whole macro if the answer is "Yes"...how do I end
the IF statement...right now it looks like...

resp = MsgBox("Do you want to run the macro?", vbYesNo, Confirm)
If resp = vbNo Then
MsgBox ("Macro stopped.")
Exit Sub

If resp = vbYes Then
Run = macro???????????
End If
 
E

Elise148

What if the IF statement is IN macro1? Will the "yes" part cause the IF
statement to run AGAIN in the macro? Is there a way to tell it to continue
with the macro, instead of run it from the beginning??
 
T

Toppers

just code the vbNO response and the macro will continue on the next statement

resp = MsgBox("Do you want to run the macro?", vbYesNo, Confirm)
If resp = vbNo Then
MsgBox ("Macro stopped.")
Exit Sub
End if

.... macro continues here ...

HTH
 
E

Elise148

Thanks soo much! Again!

Toppers said:
just code the vbNO response and the macro will continue on the next statement

resp = MsgBox("Do you want to run the macro?", vbYesNo, Confirm)
If resp = vbNo Then
MsgBox ("Macro stopped.")
Exit Sub
End if

... macro continues here ...

HTH
 
Top