+ Reply to Thread
Results 1 to 4 of 4

Adding length to For Next loop after starting

  1. #1
    Registered User
    Join Date
    06-04-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    6

    Adding length to For Next loop after starting

    I wrote a script to add spacing between sets of rows with common data.

    I set a = number of rows in the spreadsheet then use

    For x = 2 to a

    Every time I insert a space I follow it with

    a = a + 1

    but the script will only execute to the original value of "a" and not the updated one. How can I force the For Next loop to recognize that "a" has changed?

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: Adding length to For Next loop after starting

    Loop backwards instead, then you won't need to worry about it.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    06-04-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Adding length to For Next loop after starting

    Thanks! I'll change it.

    But just out of curiosity, is there a way to do it from top down?

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: Adding length to For Next loop after starting

    Yes - you could use a Do...Loop construction instead.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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