+ Reply to Thread
Results 1 to 7 of 7

How do debug a loop?

  1. #1
    Forum Contributor
    Join Date
    04-01-2010
    Location
    USA
    MS-Off Ver
    Office 2021
    Posts
    185

    How do debug a loop?

    I'm running code that includes several loops and am getting an error that says:

    "Run-time error '13':

    Type mismatch"

    When I get back to the code it doesn't highlight anything or give any indication of where the error is.

    The loop puts calculated values into excel, so I can tell around where in the loop the error occurs from that. However, I can't easily determine the line of code that's causing the problem.

    Is there a way to quickly jump to the error?

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: How do debug a loop?

    Hi,

    for me the following line is highlighted:
    Please Login or Register  to view this content.
    caused when ArrayCount = 146 as ProRata(146) is empty because the first loop ends at 145..
    Please use [CODE]-TAGS
    When your problem is solved mark the thread SOLVED
    If an answer has helped you please click to give reputation
    Read the FORUM RULES

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How do debug a loop?

    Yikes! Can you post a sample spreadsheet? (Just go to advanced and click on the paper clip)
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Forum Contributor
    Join Date
    04-01-2010
    Location
    USA
    MS-Off Ver
    Office 2021
    Posts
    185

    Re: How do debug a loop?

    It didn't highlight on mine, but I changed it to 176 and it runs now. The logic is wrong somewhere since it outputs some values to the wrong location, but at least it runs all the way through. I'll try to fix it myself before reposting.

    Quote Originally Posted by tehneXus View Post
    Hi,

    for me the following line is highlighted:
    Please Login or Register  to view this content.
    caused when ArrayCount = 146 as ProRata(146) is empty because the first loop ends at 145..

  5. #5
    Forum Contributor
    Join Date
    04-01-2010
    Location
    USA
    MS-Off Ver
    Office 2021
    Posts
    185

    Re: How do debug a loop?

    Loop Calc Excel Forum Example updated.xlsx

    Here is an example. Line 8 in the sample is where line 176 is in the actual one.

  6. #6
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: How do debug a loop?

    I'm no expert, but when I run into this situation:

    1. I put a 'debug.print' statement in the loop to find out how many loops completed. The immediate window (CTRL G)
    in the debugger will display the output.

    For example:

    Please Login or Register  to view this content.
    2. Say you find that it stops after '45' is printed.

    Modify the code to start the debugger on arraycount 45. I either of two techniques:

    Please Login or Register  to view this content.

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How do debug a loop?

    I got the same result as tehneXus - there's an actual file that I could download??

+ 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] Debug: How to debug this code?
    By reach78 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-25-2013, 07:16 AM
  2. [SOLVED] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  3. DeBug
    By Ollie in forum Excel General
    Replies: 4
    Last Post: 04-28-2006, 10:25 AM
  4. Debug this?
    By hke in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-11-2005, 11:31 AM
  5. help with debug
    By Rusty in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 02-02-2005, 12:06 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