Breakout one cell into various rows

LVExcel

Board Regular
Joined
Nov 23, 2011
Messages
59
Office Version
  1. 365
Platform
  1. Windows
I received this data (with thousands of records), where Tracking numbers are stored in a single cell and need a row for each tracking number with adjacent cell's data copied to each row.
My problem is that Tracking numbers have no space between them or comas in order to do Text To Column and then Transpose to rows.
Can someone please help me with this.

Tracking Nos
Cartons
WghtFreight
5845717537626
5845717538850
5845717539309
5845717537578​
4​
33.2​
65.34​
4845717973809
4845717970729
4845717976326
4845717976175
4845717977594
4845717979211​
6​
76.4​
155.84​
3846112383761
3846112385190
3846112387171​
3​
47.4​
62.33​
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try below VBA code assuming data starts in cell A1 and column B (Cartons) shows the total number of tracking numbers that are stored in a single cell in column A
VBA Code:
Sub test()

Dim a
a = [a1].CurrentRegion.Value2
ReDim b(1 To [sum(b:b)], 1 To UBound(a, 2))

For x = 2 To UBound(a)
    For y = 0 To UBound(Split(a(x, 1), vbLf))
        i = i + 1
        For z = 2 To UBound(a, 2)
            b(i, 1) = Split(a(x, 1), vbLf)(y)
            b(i, z) = a(x, z)
        Next
    Next
Next

With Sheets.Add(, ActiveSheet)
    .[a1:d1] = [{"Tracking Nos","Cartons","Wght","Freight"}]
    .Columns(1).NumberFormat = "@"
    .[a2].Resize(i, UBound(b, 2)) = b
    .[a1].CurrentRegion.Columns.AutoFit
End With

End Sub
 
Upvote 0
Solution
Try below VBA code assuming data starts in cell A1 and column B (Cartons) shows the total number of tracking numbers that are stored in a single cell in column A
VBA Code:
Sub test()

Dim a
a = [a1].CurrentRegion.Value2
ReDim b(1 To [sum(b:b)], 1 To UBound(a, 2))

For x = 2 To UBound(a)
    For y = 0 To UBound(Split(a(x, 1), vbLf))
        i = i + 1
        For z = 2 To UBound(a, 2)
            b(i, 1) = Split(a(x, 1), vbLf)(y)
            b(i, z) = a(x, z)
        Next
    Next
Next

With Sheets.Add(, ActiveSheet)
    .[a1:d1] = [{"Tracking Nos","Cartons","Wght","Freight"}]
    .Columns(1).NumberFormat = "@"
    .[a2].Resize(i, UBound(b, 2)) = b
    .[a1].CurrentRegion.Columns.AutoFit
End With

End Sub
Hi Mse330, don’t know how you figured it out, but WOW!! that worked like a charm from the first try. Thanks so much, I will save it for future use on other files. I really appreciate this. Thanks for taking the time.
 
Upvote 0
Glad I was able to help & thanks for the feedback :)
 
Upvote 0

Forum statistics

Threads
1,215,352
Messages
6,124,449
Members
449,160
Latest member
nikijon

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