Results 1 to 4 of 4

Inserting rows whilst executing a “For” loop

Threaded View

  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?
    Dim FinalRow            As Integer
    Dim i                       As Long
    .
    .
    FinalRow = Cells(65536, 1).End(xlUp).Row
    For i = 2 To FinalRow
    .
    .
     i = i + 1
     Cells(i, 1).Select
     ActiveCell.EntireRow.Insert shift:=xlDown
     FinalRow = FinalRow + 1
    .
    .
    Next i
    Last edited by royUK; 04-24-2008 at 05:55 AM.

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