+ Reply to Thread
Results 1 to 11 of 11

Debug: How to debug this code?

  1. #1
    Registered User
    Join Date
    09-09-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    35

    Debug: How to debug this code?

    Hi All,

    I've written a macro that is supposed to do the following once it is execute:

    1) Requests the user to click on a cell (to get its row value)
    2) Use the row value to get a range of values over 3 cells in steps of 5 across the column (essentially I'm taking data values across a table whose type repeats itself every 5 columns)
    3) Pasting the values in a table in a different sheet but down a row instead of across a column

    The code compiles and executes but I get no values in the target table. There isn't even an error. So I'm wondering, how does one go about debugging the thing?

    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    09-09-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Debug: How to debug this code?

    I think the idea for me to debug is to find out what the values of TrendRng and RptVal hold at any one time. I tried debug.print but somehow couldn't get it to work...any ideas?

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

    Re: Debug: How to debug this code?

    Hi,

    My favorite explanation is on http://www.cpearson.com/Excel/DebuggingVBA.aspx

    You set a breakpoint on the "Set Point" line by clicking in the left margin of that line. Then you run the code and step through it. You can hold the cursor over any variables and it will display their current values.

    Read the webpage.. Hope that helps. If not keep asking and perhaps attach your workbook so we can look at it..
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    09-09-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Debug: How to debug this code?

    Found the issue. The code is printing the values into the next sheet but its all over the place and it is not iterating as I thought it would...

    Using the 'step' debug key (F8), I found that the code was spending most of the time in the For x loop rather than running through the 'For i then...' loop then 'For x then' loop and repeating at the 'For i then...' loop if you get what I mean. Maybe it has to do with the placement of the next i, next x lines....I'll experiment with it but if anyone has an improvement suggestion I'm all ears

  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Debug: How to debug this code?

    I don't understand the For x loop at all. For each set of values found in the For i loop, you repopulate the same 12 rows of cells in the For x loop?
    Remember what the dormouse said
    Feed your head

  6. #6
    Registered User
    Join Date
    09-09-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Debug: How to debug this code?

    Hi romperstomper,

    I'll illustrate the intention of my macro with a picture --> macro-intention.jpg

    Thanks.

    reach

  7. #7
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Debug: How to debug this code?

    A picture is of no use for testing...

  8. #8
    Registered User
    Join Date
    09-09-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Debug: How to debug this code?

    Well here's the xlm file :p

    https://docs.google.com/file/d/0BxMi...it?usp=sharing

    It is the GenerateReport macro within it.
    Last edited by reach78; 09-24-2013 at 02:54 AM.

  9. #9
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Debug: How to debug this code?

    I think you just need one loop:
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    09-09-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Debug: How to debug this code?

    Thanks romperstomper. That worked!
    Rep added!


    However, could you explain what this does?

    Please Login or Register  to view this content.
    reach
    Last edited by reach78; 09-24-2013 at 07:06 PM.

  11. #11
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Debug: How to debug this code?

    This part:
    Please Login or Register  to view this content.
    refers to one cell, then using .Resize(, 3) resizes that to include the two cells to the right so you have a 3 cell range.

+ 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. Debug single line of code
    By aloha31 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-30-2013, 02:06 PM
  2. [SOLVED] VBA Code Debug Error
    By Jennsy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-19-2012, 08:55 AM
  3. Problem trying to debug some code
    By Exadore in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-07-2011, 05:28 PM
  4. Debug the Code
    By macrogeek in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-17-2011, 06:45 AM
  5. HELP, trying to debug this code...
    By twofootgiant in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-18-2011, 12:05 PM

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