Insert, replicate rows based on column value

August 31, 2010 at 01:57:02
Specs: Windows Vista

I'm in need of help with a macro. I have data in three columns. The third column (Column C) titled 'count' has numbers. Each row has to be repeated again as many times as is specified in the number column, i.e, if in C2 the value in 5, I need 5 rows inserted below Row2, and data from Row2 to be copy pasted into these. This action needs to be carried out for the entire data set. Could somebody please help me?

See More: Insert, replicate rows based on column value

Report •

August 31, 2010 at 13:03:03
Instead of reinventing the wheel, I modified some code that Humar offered in this thread.

Thank Humar...he did most of the work.

Public Sub InsBelow()
Dim lngStartRow As Long
Dim lngEndRow As Long
Dim m As Integer
Dim n As Long

With ActiveSheet
    'work from bottom up
    'set start row
    lngStartRow = Range("C" & CStr(Application.Rows.Count)).End(xlUp).Row
    'set end row
    lngEndRow = 2
    'loop through all used rows in column E starting at bottom
    For n = lngStartRow To lngEndRow Step -1
        If IsNumeric(Range("C" & CStr(n)).Value) Then
            'insert rows below
            For m = 1 To Range("C" & CStr(n)).Value
                Rows(n + 1).Insert shift = xlDown
            Next m
        End If
    Next n
End With
End Sub

Report •

September 1, 2010 at 10:10:03
Thanks very very very much..... both to you and to Humar!

Report •

September 1, 2010 at 11:38:56
I'm glad I...errr...I mean Humar could be of assistance. ;-)

Report •

Related Solutions

September 1, 2010 at 12:52:37

Glad to know I have been of assistance - "in absentia".



Report •

Ask Question