none
how to run a macro from specific line in the middle of the code to end of the code in VBA

    Question

  • hi frineds

    imagine we have the following Macro in VBA 

    sub  Macro1

    line 1

    line 2

    line 3

    line 4

    line 5

    end sub

    how can i run from line 3 to end ?

    i didn't find any solution in Debug menu to do this

    thanks in advanced

    Wednesday, November 5, 2014 8:49 AM

Answers

  • Click anywhere in Macro1.

    Press F8 to start single-step mode.

    There will be a yellow arrow to the left of the line Sub Macro1().

    Drag this arrow down to the line where you want to start. Make sure that it makes sense to begin here!

    Press F5 to run.


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Wednesday, November 5, 2014 4:56 PM

All replies

  • Click anywhere in Macro1.

    Press F8 to start single-step mode.

    There will be a yellow arrow to the left of the line Sub Macro1().

    Drag this arrow down to the line where you want to start. Make sure that it makes sense to begin here!

    Press F5 to run.


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Wednesday, November 5, 2014 4:56 PM
  • We know this step, please can you suggest any other way..

    Sometimes codes would be 120 lines or more..

    Monday, October 30, 2017 2:44 PM
  • What do you want to accomplish?

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Monday, October 30, 2017 9:41 PM
  • We know this step, please can you suggest any other way..

    Sometimes codes would be 120 lines or more..

    Split window with code (using little button over scrollbar) and drag yellow arrow between them.

    Thursday, November 9, 2017 9:07 AM
  • It happens to me a lot as well.

    My solutions:

    isolate code you want to run with something like:

    "End sub

    Sub Test20934924()  'some random number, make sure never matches previous code sections

    ## TEST CODE HERE ##

    end sub

    Sub Test2394854924() "


    If you are happy with the code, it's your choice to keep the isolating code (by commenting them effectively they will no longer stop your code)  or delete them. I suggest that while still in development keep them in "commented" state as they may become handy again. 




    Friday, May 4, 2018 8:02 AM
  • Other solution:

    copy paste code section to separate (new/tests) module and test it from there.

    Friday, May 4, 2018 8:04 AM
  • After you have started debugging your macro if you put your cursor on the line that you want to debug to hold  ctr and hit F5 and you will go to this line


    Wednesday, November 28, 2018 11:15 PM
  • I know this is a super old post, but what you want to do is start the debugging process, place your cursor on the line you want to skip to (where you want the yellow highlight to be WITHOUT dragging it), then press CTRL + F9.

    This helps if you're debugging thousands of lines of code. 

    Thursday, April 4, 2019 4:01 PM