+ Reply to Thread
Results 1 to 10 of 10

VBA Skipping lines of code.

  1. #1
    Registered User
    Join Date
    03-15-2017
    Location
    United States
    MS-Off Ver
    2016
    Posts
    63

    VBA Skipping lines of code.

    I have already done some research and seen what people have posted in the past and I cannot find a solution to this problem. Here is my code. Its pretty simple and bare.

    Please Login or Register  to view this content.
    You can test this code with 2 blank sheets. It never reads the If r = 1092 And n = 311 Then. Why does it do this? I mentioning this line because if it read this line, then it would execute the other if statement above. But it skips just about all of it, but counts correctly in debug.print.

    Edit: Also, if I run the entire code using F8 then it works like it's suppose to.
    Last edited by schulzy175; 02-15-2018 at 03:14 PM. Reason: Added Note

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,309

    Re: VBA Skipping lines of code.

    Without data, it's difficult to know what is happening. Best guess is it's hitting the Exit For condition.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Re: VBA Skipping lines of code.

    Quote Originally Posted by TMS View Post
    Without data, it's difficult to know what is happening. Best guess is it's hitting the Exit For condition.
    Yep. I tested here on a 2 blank sheets. Removing the Exit fixes the issue.

    But you are doing ALOT of looping here. Each loop of r runs 315 times for n to finish.

    346,185 loops on that code !!
    Last edited by ptmuldoon; 02-15-2018 at 03:39 PM.

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,767

    Re: VBA Skipping lines of code.

    If you have 2 blank sheets then this line
    Please Login or Register  to view this content.
    will always be true. Therefore N will only ever =1

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

    Re: VBA Skipping lines of code.

    For one thing the msgbox code should be relocated:

    Please Login or Register  to view this content.
    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

  6. #6
    Registered User
    Join Date
    03-15-2017
    Location
    United States
    MS-Off Ver
    2016
    Posts
    63

    Re: VBA Skipping lines of code.

    Thanks for all the help! Yes, the Exit For was causing the issue oddly enough, but considering the large loop. lol, Yes, I am cross-referencing a lot of invoices. I did 9000x9000 which took almost 7 hours. So this thread is definitely solved, but as for the looping for so many cells, any suggestions on speeding up a cross-reference with so many cells?

  7. #7
    Registered User
    Join Date
    03-15-2017
    Location
    United States
    MS-Off Ver
    2016
    Posts
    63

    Re: VBA Skipping lines of code.

    xladept,

    my apologies, I should have mentioned that the msgbox was a debug for the issue seeing if it ever executed that line. If that line was executed, I know the code was working.
    Last edited by jeffreybrown; 02-17-2018 at 07:46 PM. Reason: Removed full quote!

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

    Re: VBA Skipping lines of code.

    I forgive you - the formatting is, obviously, what takes all the time.

  9. #9
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,767

    Re: VBA Skipping lines of code.

    This should be somewhat quicker
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    03-15-2017
    Location
    United States
    MS-Off Ver
    2016
    Posts
    63

    Re: VBA Skipping lines of code.

    Fluff13,

    Ooo, I'll definitely try that. That is some new stuff I haven't come across yet. Thanks. And thanks everyone else for your help as well.
    Last edited by jeffreybrown; 02-17-2018 at 07:47 PM. Reason: Removed full quote!

+ 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] Is VBA skipping lines of code?
    By JonathanEngr in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-21-2018, 06:48 PM
  2. [SOLVED] Sub is skipping lines of code after Then statement
    By chavez982 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-05-2012, 10:32 PM
  3. [SOLVED] How do I allow for skipping lines between dates??
    By n2music in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-10-2012, 10:28 AM
  4. return results without skipping lines.
    By mjhopler in forum Excel General
    Replies: 2
    Last Post: 07-13-2010, 04:01 AM
  5. Copy a formula skipping lines
    By JapanDave in forum Excel General
    Replies: 3
    Last Post: 06-01-2010, 05:11 AM
  6. [SOLVED] Need help in numbering a column while skipping lines
    By Gary Reger in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-21-2005, 06:10 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