Reorganise data onto different rows based on separator

ellison

Active Member
Joined
Aug 1, 2012
Messages
356
Office Version
  1. 365
Platform
  1. Windows
Hi, I'm wondering if there's a way that I can reorganise the data as below?

The data in Column B separates the different strings using ";"

And we'd like to separate each string of data out onto its own row, with its original Line ID?

Preferably on a separate results sheet, if at all poss :-)


Line_IDData Results (preferably on a different sheet):Line_IDData_V1
4orange;black;546324orange
12black;Grey4black
812222_4;WHITE;red454632
12black
12Grey
812222_4
81WHITE
81red
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Line_IDDataLine_IDData
4orange;black;546324orange
12black;Grey4black
812222_4;WHITE;red454632
12black
12Grey
812222_4
81WHITE
81red

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Split = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Data", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Data")
in
    Split
result table can be loaded wherever you want
 
Upvote 0
a-ha a power query!
It's about time I tried to figure out how to use these, will have a play and get back to you.
Wish me luck!
 
Upvote 0
Hi, can I just ask.. how do I enter this onto the powerquery?

So far, I've created a fresh workbook, set up a powerquery, chosen the file with the table of original data (as above) and now I can either hit "load" or "transform"...

Am I on the right lines?!?!
 
Upvote 0
nooooo...
you've a table (if this is a range select it then use Ctrl+T to make it Excel Table)
then on Data tab find From Table
it will open PQ Editor
then
split.png
 
Upvote 0
Some VBA if you can't get the query to work for you.

VBA Code:
Sub t()
Dim i As Long, spl As Variant
With ActiveSheet
    For i = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
        spl = Split(.Cells(i, 2), ",")
        Sheets(2).Cells(Rows.Count, 1).End(xlUp)(2).Resize(UBound(spl) + 1) = .Cells(i, 1).Value
        Sheets(2).Cells(Rows.Count, 2).End(xlUp)(2).Resize(UBound(spl) + 1) = spl
    Next
End With
End Sub
 
Upvote 0
Some VBA if you can't get the query to work for you.

VBA Code:
Sub t()
Dim i As Long, spl As Variant
With ActiveSheet
    For i = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
        spl = Split(.Cells(i, 2), ",")
        Sheets(2).Cells(Rows.Count, 1).End(xlUp)(2).Resize(UBound(spl) + 1) = .Cells(i, 1).Value
        Sheets(2).Cells(Rows.Count, 2).End(xlUp)(2).Resize(UBound(spl) + 1) = spl
    Next
End With
End Sub

Huge thanks for this....

I'm getting an error when I run this and when I hit debug, the line it highlights:

Sheets(2).Cells(Rows.Count, 1).End(xlUp)(2).Resize(UBound(spl) + 1) = .Cells(i, 1).Value
 
Upvote 0
ellison
A really good primer is "M is for (Data) Monkey" by Ken Puls and Miguel Escobar available in the Mr E store and Amazon.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,215
Members
453,024
Latest member
Wingit77

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