+ Reply to Thread
Results 1 to 4 of 4

Inserting rows whilst executing a “For” loop

  1. #1
    Registered User
    Join Date
    04-24-2008
    Posts
    2

    Inserting rows whilst executing a “For” loop

    Hi,

    This is my first ever post as I'm new to VBA, so forgive any sloppy code or inadvertant breach of etiquette.

    My problem is I’m not able to influence the ending row (where the loop stops) of a ‘For’ loop to reflect rows inserted during its execution.

    I am writing a spreadsheet macro where there will be a different number of rows each time it is run. My macro correctly determines the final row and then runs a ‘For’ loop to process every row.
    When I encounter a change of, in this case a contract number I insert a line and I then increment my counter and the variable holding the row count by one.

    The problem is that the execution still stops when the current row is equal to the starting value of the variable final row – stopping short of the last row. How do / can I influence where the loop stops once I’m in the loop?
    Please Login or Register  to view this content.
    Last edited by royUK; 04-24-2008 at 05:55 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Welcome to the Forum.I have added code tags for you please click the edit button at the bottom of your post to see how it's done.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I think this might be what you want, note I have changed i to a Long because the number of rows may exceed an integer's value. This code will add a new row between each entry, you need to start from the last row & work back.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    04-24-2008
    Posts
    2
    Hi RoyUK,

    Appreciate your guidance and response. many thanks.

+ 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