VBA Code ... Run-skip-run ... Code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Excel2003 ... I have Macros (note: I record only, then cut/paste) where I
have a MsgBox (YES/NO) where ... YES = continue running Macro ... NO = Exit
Sub ... These work fine ...

However, in addition to above ... I would like simplified Code that will
allow for ... Run/Skip/Run ... in addition to Run/Exit (above).

ie: I have 1000 lines of Code & I want a YES/NO option to run lines 400-600
or skip these lines ... Run Macro =

Run lines 1-399 ...
YES/NO Msg Box ...
YES = Continue running lines 400-1000
NO = Skip lines 400-600 ... resume running @ line 601-1000

Note: I need capability to edit the YES/NO & what is Run/Skipped so I can
use these edited lines of Code in other Macros where I wish to ...
Run/Skip/Run ...

Gord Dibben has provided a lot of guidance (separate post & my sincere
Thanks) ... However, based on his latest response I am now posting this
question to the Programmers ... Thanks ... Kha
 
The structure would look something like this:

Run lines 1-399
If YES/NO Msg Box = YES Then
lines 400-1000
End If
Run lines 601-1000

If you have a 1000 line macro you may want to invest some time learning more
about VBA than just recording. The recorded code can get the job done, but
almost never in the most efficient or flexible way.
 
Rather than testing for a=7 (or vbNo), test for a =vbYes. If a does =
vbYes, the code between the IF and END IF statements will be executed,
otherwise they will be skipped and execution will pick-up after the End If.
Something like this (I replaced the 6/7 with vbYes/vbNo for programming
clarity).

a = MsgBox("Text" + Chr(13) + Chr(13) + "Text" + Chr(13) + Chr(13) + "Text",
vbYesNo, "ATTENTION!!!")

If a = vbYes Then
Execute lines 400-600
End If

Execute Lines 601-1000
 

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