Results 1 to 20 of 23

Thread: Insert a new row after a certain number of rows

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #13
    VBAX Regular
    Joined
    Dec 2006
    Posts
    18
    Location
    Quote Originally Posted by mdmackillop
    try
    [vba]Option Explicit

    Sub AddRows()
    Dim LRw As Long
    Dim rng As Range
    Dim i As Long

    Application.ScreenUpdating = False
    LRw = Cells(Rows.Count, 1).End(xlUp).Row - 38
    For i = LRw To 4 Step -39
    Set rng = Union(Cells(i + 9, 1), Cells(i + 18, 1), Cells(i + 22, 1), _
    Cells(i + 29, 1), Cells(i + 32, 1), Cells(i + 39, 1))
    rng.EntireRow.Insert
    Set rng = Nothing
    Next
    Application.ScreenUpdating = True
    End Sub
    [/vba]
    I tried it. But the new rows are inserted at the wrong places. My first row (or first customer) starts at row4, 2nd starts at row 43, 82 and so on.

    For my first customer, I need to insert new rows at row 13, 23, 28, 36,40 and 43. For my second customers, new rows need to be inserted at 13+39, 23 +39.....43+39.

    If you could, please explain the code, so maybe I could try to modify it or..test it. I tried to change those numbers in the brackets, still no luck.

    Not sure if this helpful, but there might be a empty space at row 13, 23, or 28. Because other columns at row 13, 23 or 28 might have data in them, I am trying to insert a row so.. all columns are empty.

    Thanks in advance.
    Last edited by tialongz; 12-18-2006 at 01:38 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •