+ Reply to Thread
Results 1 to 3 of 3

VBA For Loop skipping internal executions

  1. #1
    Registered User
    Join Date
    03-07-2013
    Location
    Long Beach, WA
    MS-Off Ver
    Excel 2013
    Posts
    87

    VBA For Loop skipping internal executions

    I'm bringing data in from a download and it appears in reverse row order to what I need. This seems like a very common situation so I was trying to either find or write a subroutine for the purpose of reversing the row order.
    So, the "specification" could be: copy a range in one sheet and paste it in another sheet with the row order reversed.
    One can meet this need by creating a sorting macro but the strangeness here seems good to be investigated.
    Here is the code with the short loop near the end:
    Please Login or Register  to view this content.
    The code is intended to take the last row of the original data and put it in the first row of the destination and iterate from there.
    Instead, it takes the last row of the original data and puts it in the 2nd row of the destination - skipping the first row of the destination altogether.
    After that, the iteration continues as it should but ends one row too many in the destination as one might expect if the first action is delayed.

    The Debug.Print statements in the loop are helpful. I watch the destination sheet in a separate screen to confirm all this happening.
    Changing DestRow value to 1 seems to fix it but I don't know why. Seems a good opportunity for learning.

    Thank you!!

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,215

    Re: VBA For Loop skipping internal executions

    As "DestRow" is initialised as 2, it will place it in row 2!

    Please Login or Register  to view this content.
    Changing DestRow value to 1 seems (??) to fix it
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Registered User
    Join Date
    03-07-2013
    Location
    Long Beach, WA
    MS-Off Ver
    Excel 2013
    Posts
    87

    Re: VBA For Loop skipping internal executions

    John,

    Thank you!. One can't argue with your English. I thought of something like that which caused me to experiment setting it to "1". The obvious question is: Does that row number apply to the sheet or to the range? How does one know in this case? So, one has to *guess* (if they are as ignorant as I am on this) that it's the 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. [SOLVED] Loop is skipping iterations
    By Jovica in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-22-2014, 06:50 AM
  2. [SOLVED] Skipping over certain sheets in a For Each loop
    By NicholasL in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-12-2013, 03:15 PM
  3. Skipping Loop
    By yasar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-22-2013, 06:15 AM
  4. Skipping first row in a Loop
    By johnph in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-05-2012, 11:42 AM
  5. Loop is skipping rows
    By Rodrigofrb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-22-2011, 05:05 PM
  6. End a DO WHILE LOOP WITH INTERNAL IF STATMENT?
    By 77anders in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-06-2009, 04:54 AM
  7. Skipping cells in a Do Until loop
    By medicenpringles in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-28-2005, 11:42 AM
  8. Do loop skipping
    By medicenpringles in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-27-2005, 10:05 PM

Tags for this Thread

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