+ Reply to Thread
Results 1 to 4 of 4

Add X number of rows based on value of cell

Hybrid View

  1. #1
    Registered User
    Join Date
    05-24-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    7

    Add X number of rows based on value of cell

    Hi

    I want to insert C rows of each ID from column A. The number of rows I want inserted differ for each ID.

    Sample workbook is attached.

    Cheers,
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    11-20-2012
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2010
    Posts
    597

    Re: Add X number of rows based on value of cell

    Sub addCrows()
    
    strLastCrow = CStr(Range("C" & CStr(Application.Rows.Count)).End(xlUp).Row)
    
    'inserts the desired number of rows
    For c = strLastCrow To 2 Step -1
        r = Range("C" & c).Value
        rs = c + r
        Range("C" & c & ":" & "C" & rs).Offset(1).EntireRow.Insert
    Next
    
    'fills in the id number
    strLastArow = CStr(Range("A" & CStr(Application.Rows.Count)).End(xlUp).Row)
    
    For c = 2 To strLastArow Step 1
        If Range("A" & c) = "" Then Range("A" & c).FillDown
    Next
    
    
    End Sub

  3. #3
    Registered User
    Join Date
    05-24-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Add X number of rows based on value of cell

    It adds one too many rows, but I can just dial the number down one.

    Thanks a bunch I'll see if it works on the larger data set.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Add X number of rows based on value of cell

    On your sample, you have one more rows than the numbers on the column C.

+ 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