create Multiple Rows per line item

peedeebee

New Member
Joined
Jun 26, 2018
Messages
8
Hello, I am trying to convert some data currently exported as below:

Order NumberSKUPrice
Order1sku1,sku2$1,$2
Order2sku3,sku4$1,$2

<tbody>
</tbody>

We need this transformed in excel into something like the below:

Order NumberSKUPrice
Order1sku1$1
Order1sku2$2
Order2sku3$1
Order2sku4$2

<tbody>
</tbody>

Any help would be greatly appreciated!

Thanks!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Welcome to the forum!

Here's a macro that assumes your starting data are in cols A:C with the first header in A1. The rearranged data are in cols E:G starting in E1 as shown below.
Excel Workbook
ABCDEFG
1Order NumberSKUPriceOrder NumberSKUPrice
2Order1sku1,sku2$1,$2Order1sku1$1
3Order2sku3,sku4$1,$2Order1sku2$2
4Order3sku1$2Order2sku3$1
5Order2sku4$2
6Order3sku1$2
Sheet7



Code:
Sub RearrangeData()
Dim R As Range, c As Range, nxRw As Long, V1 As Variant, V2 As Variant
Set R = Range("A1:C" & Cells(Rows.Count, "A").End(xlUp).Row)
Application.ScreenUpdating = False
Range("E:G").ClearContents
With Range("E1:G1")
    .Value = R.Rows(1).Cells.Value
    .EntireColumn.AutoFit
End With
For Each c In R.Offset(1, 0).Resize(R.Rows.Count - 1).Columns(1).Cells
    V1 = Split(c.Offset(0, 1).Value, ",")
    V2 = Split(c.Offset(0, 2).Value, ",")
    nxRw = Range("E" & Rows.Count).End(xlUp).Row + 1
    If UBound(V1) > 0 Then
        With Range("E" & nxRw)
            .Resize(UBound(V1) + 1).Value = c.Value
            For i = LBound(V1) To UBound(V1)
                .Offset(i, 1).Value = V1(i)
                .Offset(i, 2).Value = V2(i)
            Next i
'            .Offset(0, 2).Resize(UBound(V) + 1).Value = c.Offset(0, 2).Value
        End With
    Else
        Range("E" & nxRw).Resize(1, 3).Value = c.Resize(1, 3).Value
    End If
Next c
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Sorry about that! It’s just a link to the excel in onedrive. I didn’t think you had to download to view. I will use one of the tools you mentioned and post.
 
Upvote 0

Forum statistics

Threads
1,215,644
Messages
6,125,991
Members
449,278
Latest member
MOMOBI

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