Creating Copies of a Row and filtering a value

Brenkenathan

Board Regular
Joined
Sep 19, 2002
Messages
146
OK, I am lost on how to do something as I am not strong with macros BUT I think you guys maybe able to save me hours of work.

I have an output spreadsheet that has roughly 100 rows of data.
In column D I was suppose to have a Name but I now have a listing of name some have 2 names some up to 8 names that are separated with a carriage return
In Column C I have the count of how many values are in Column D

What I need is each row copied X amount of times where X = the number is Column C
And when each is copied I need the value in D to be unique to that list so if it had values X and Y in column D. I now need D1 = X and D2 = Y

Can anyone help because manually this could take HOURS of work
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try this
Code:
Sub CopySplitOnCell()

    Dim Cnt As Long
    Dim Splt As Long
    Dim Qty As Long

Application.ScreenUpdating = False

    For Cnt = Range("D" & Rows.Count).End(xlUp).Row To 2 Step -1
        If Range("C" & Cnt).Value > 1 Then
            Splt = Range("C" & Cnt).Value
            Rows(Cnt).copy
            Rows(Cnt).Resize(Splt - 1).Insert
            For Qty = 0 To Splt - 1
                Range("D" & Cnt + Qty).Value = Split(Range("D" & Cnt + Qty), Chr(10))(Qty)
            Next Qty
        End If
    Next Cnt

End Sub
 
Upvote 0
Slightly better method would be
Code:
Sub CopySplitOnCell()

    Dim Cnt As Long
    Dim Splt As Long
    Dim Qty As Long

Application.ScreenUpdating = False

    For Cnt = Range("D" & Rows.Count).End(xlUp).Row To 2 Step -1
        If Range("C" & Cnt).Value > 1 Then
            Splt = Range("C" & Cnt).Value
            Rows(Cnt).copy
            Rows(Cnt).Resize(Splt - 1).Insert
                Range("D" & Cnt).Resize(Splt).Value = Application.Transpose(Split(Range("D" & Cnt), Chr(10)))
        End If
    Next Cnt
Application.CutCopyMode = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,231
Messages
6,123,754
Members
449,119
Latest member
moudenourd

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top