+ Reply to Thread
Results 1 to 4 of 4

Maybe silly question: Is it possible to only execute part of a macro for debug purposes?

  1. #1
    Registered User
    Join Date
    06-11-2012
    Location
    Calgary
    MS-Off Ver
    Excel 2007-2010
    Posts
    25

    Maybe silly question: Is it possible to only execute part of a macro for debug purposes?

    Hi there.

    So. Let's say I'm still in the process of writing my macro. I run it, everything works. I add a few lines of code and want to make sure the new lines of code work.

    As far as I know, the only way to test the new code I wrote is to run the entire macro again? If I try to put the cursor on the first new line and step through the code with F8, it always jumps to the beginning of the code. I'd really like to just run those last lines that I added if there's any way to do that. I already know the rest of the code works, after all. Am I missing a way to do this?

    Thanks in advance.

    Edit for tl;dr: I know how to run only part of the macro IF I want to start at the beginning and step through or set a break point. But I want to start in the middle somewhere.
    Last edited by Shanyn; 02-03-2015 at 10:09 PM.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Maybe silly question: Is it possible to only execute part of a macro for debug purpose

    Hey Shanyn,

    Have you tried those few lines of code in the immediate window?

    I do this lots of times.

    For example: A few days ago in the middle of a macro I wanted to clear contents for columns A, B and C. I know there are different ways to select the entire column but tried a few in the Immediate Window.

    Columns(A,B,C).select 'didn't work
    Columns("1:3").select 'didn't work either
    Columns("A:C").select 'works but is there an easier way?
    Range(cells(1,"A"),cells(1,"C")).entirecolumn.select ' Excel also likes this line

    All the above are tried in the Immediate window to see if VBA will like them before sticking them into my REAL code.

    I think you get what I'm hinting at.
    Last edited by MarvinP; 02-03-2015 at 10:42 PM.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    06-11-2012
    Location
    Calgary
    MS-Off Ver
    Excel 2007-2010
    Posts
    25

    Re: Maybe silly question: Is it possible to only execute part of a macro for debug purpose

    I'm self-taught and had never heard of the Immediate Window. Thanks for giving me a new search term to fawn over. That looks like it will work okay.

  4. #4
    Guest
    Join Date
    01-02-2015
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    30

    Re: Maybe silly question: Is it possible to only execute part of a macro for debug purpose

    Hi,
    what you can do is use a goto at the top of your code, perhaps put it after any declarations/Dims, or not it's up to you, but if your code requires them it will fail.

    and then point it to were you want to start.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Silly little question regarding cel formatting
    By Kym-B in forum Excel General
    Replies: 1
    Last Post: 12-05-2013, 08:46 AM
  2. [SOLVED] Silly Question !!
    By DanielRay in forum The Water Cooler
    Replies: 4
    Last Post: 12-08-2012, 04:49 PM
  3. Silly Question !!
    By DanielRay in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-07-2012, 11:41 AM
  4. Hello! Liz from Detroit, MI - SILLY question!
    By libby1972 in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 11-27-2012, 07:41 PM
  5. silly look up question
    By floricita in forum Excel General
    Replies: 1
    Last Post: 10-11-2010, 07:03 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1