Splitting rows into number of rows based on quantity in a cell

youdik77

New Member
Joined
Jul 12, 2017
Messages
9
Hello, I have this peculiar situation I am trying to solve.

I have an extract which contains a list of products and to compare this with another spread sheet I need the quantities for each line to be equal to one.

So I am trying to figure out a macro that would take the row and split it into the same same amount of rows based on quantity in column E (and also make total in column G equal to product value in column F). All other data from the original row would be unchanged.

ABCDEFGHIJ
1
2CLAIM EXTRACT
3
4DataDate 1Data ProductQuantityProduct valueTotalData Data Data
5aaa15-May-17cccSnake3£15.00£45.00hhhiiijjj
6aaa15-May-17cccHedgehog1£20.00£20.00hhhiiijjj
7aaa15-May-17cccMouse2£25.00£50.00hhhiiijjj
ABCDEFGHIJ
1
2CLAIM EXTRACT AFTER MACRO
3
4DataDate 1Data ProductQuantityProduct valueTotalData Data Data
5aaa15-May-17cccSnake1£15.00£15.00hhhiiijjj
6aaa15-May-17cccSnake1£15.00£15.00hhhiiijjj
7aaa15-May-17cccSnake1£15.00£15.00hhhiiijjj
8aaa15-May-17cccHedgehog1£20.00£20.00hhhiiijjj
9aaa15-May-17cccMouse1£25.00£25.00hhhiiijjj
10aaa15-May-17cccMouse1£25.00£25.00hhhiiijjj

<tbody>
</tbody><colgroup><col><col><col><col><col><col><col><col><col><col><col></colgroup>

Any tips, references, ideas would be much appreciated. Whereas I am fairly skilled in Excel analysis, I am an VBA beginner and I am trying to learn as much as possible.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hia
Give this a go
Code:
Sub InsertRows()

    Dim i As Long
    Dim UsdRws As Long
    Dim XtraRws As Integer
    
    Application.ScreenUpdating = False
    
    UsdRws = Range("A" & Rows.Count).End(xlUp).Row
    
    For i = UsdRws To 5 Step -1
        XtraRws = Range("E" & i)
        If XtraRws > 1 Then
            Range("E" & i) = 1
            Range("G" & i) = Range("F" & i)
            Rows(i).Copy
            Rows(i + 1).Resize(XtraRws - 1).Insert
        End If
    Next i
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,847
Members
449,051
Latest member
excelquestion515

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