Message Box that let's you decide when to run a block of code

VBAProIWish

Well-known Member
Joined
Jul 6, 2009
Messages
1,027
Office Version
  1. 365
Platform
  1. Windows
Hello All,

I have code (provided by VoG, thanks again VoG!) within a large procedure that I don't always want to run.
Can I pop up a message box right before that block of code that says...

"do you want to add the numbers to the master report?"

If I say yes, the code runs, If I say no, is simply skips only that part of the code and continues on with the rest of the code in the procedure.


Nutshell Version,

Code:
regular code
regular code
[COLOR=red][B]message box "Do you want to add the numbers to the master report? (yes or no)[/B][/COLOR]
[B]VoG's code below runs ONLY if "yes" is selected[/B]
Dim Rng As Range
Dim wb As Workbook
Set wb = ActiveWorkbook
Set Rng = Range("a1").CurrentRegion
Set Rng = Rng.Offset(1, 0)
Set Rng = Rng.Resize(Rng.Rows.Count - 1)
Rng.Copy
On Error GoTo puke
    Windows("History.xlsm").Activate
 
Range("A1").End(xlDown).Offset(1, 0).Select
ActiveSheet.Paste
 
 
Windows("History.xlsm").Visible = False
 
wb.Activate
puke:
END OF VoG's code 
 
regular code (this code is continued on whether the message box is skipped or not)
regular code

Can this be done?

Thanks much!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try

Code:
If MsgBox("Do you want to add the numbers to the master report?", vbYesNo + vbQuestion) = vbNo Then Exit Sub
 
Upvote 0
Thanks for the quick reponse VoG. How does the routine know exactly where to restart with the same module?

So..

Line 1 Msg box code you just provided me
Line 2 your old code
Line 3 continue with rest of code in the module (whether yes or no is selected).

Thanks
 
Upvote 0
If you click No the code exits. If you click Yes the code carries on from the line below the MsgBox line.
 
Upvote 0
Thanks VoG

Ok, I have code AFTER your code within the same module that still needs to run whether "yes" OR "no" is selected. I just want your particular code to simply be ignored if "no" is selected.

After I ran it, the message box came up and I said "no", the macro then stopped and it didn't continue to run any more of code in the module. I still need it to run the code after your code.

Hope that makes sense
 
Upvote 0
Try

Code:
If MsgBox("Do you want to add the numbers to the master report?", vbYesNo + vbQuestion) = vbNo Then GoTo Puke
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,762
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top