Transform data from rows to columns

cuinbc

New Member
Joined
Oct 29, 2018
Messages
1
[FONT=&quot]Hi all,

My raw data looks like this:[/FONT]

[FONT=&quot]The data was copied and pasted from a notepad, so each line is on a different row.

[/FONT]

[TABLE="class: yklcuq-19 cUmOil"]
<thead style="margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;">[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TH="class: yklcuq-25 kFFvu, align: center"]====Starting details=====[/TH]
[/TR]
</thead><tbody style="margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;">[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]20: abc[/TD]
[/TR]
[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]23B: def[/TD]
[/TR]
[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]32A: ghk[/TD]
[/TR]
[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]50K: lmn[/TD]
[/TR]
[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]=====Ending details=====[/TD]
[/TR]
[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]====Starting details=====[/TD]
[/TR]
[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]20: 123[/TD]
[/TR]
[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]23B: 321[/TD]
[/TR]
[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]32A: 456[/TD]
[/TR]
[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]50K: 789[/TD]
[/TR]
[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]=====Ending details=====[/TD]
[/TR]
[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]====Starting details=====[/TD]
[/TR]
[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]20: qwe[/TD]
[/TR]
[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]23B: wer[/TD]
[/TR]
[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]32A: ert[/TD]
[/TR]
[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]50K: rty[/TD]
[/TR]
[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]=====Ending details=====[/TD]
[/TR]
</tbody>[/TABLE]
[FONT=&quot]
[/FONT]


  • Please note that in reality, the details that follow the (20:, 23B:, 32A: 50K:) are all different lengths, but the details always follow 20:/23B:/32A:/50K:
  • Text to column won't work because the data is scattered on different rows.
  • I have access to power query
[FONT=&quot]I need to achieve the below:[/FONT]
[TABLE="class: yklcuq-19 cUmOil"]
<thead style="margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;">[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TH="class: yklcuq-25 kFFvu, align: center"]20:[/TH]
[TH="class: yklcuq-25 kFFvu, align: center"]23B:[/TH]
[TH="class: yklcuq-25 kFFvu, align: center"]32A:[/TH]
[TH="class: yklcuq-25 kFFvu, align: center"]50K:[/TH]
[/TR]
</thead><tbody style="margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;">[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]abc[/TD]
[TD="class: yklcuq-21 gHVYpd"]def[/TD]
[TD="class: yklcuq-21 gHVYpd"]ghk[/TD]
[TD="class: yklcuq-21 gHVYpd"]lmn[/TD]
[/TR]
[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]123[/TD]
[TD="class: yklcuq-21 gHVYpd"]234[/TD]
[TD="class: yklcuq-21 gHVYpd"]456[/TD]
[TD="class: yklcuq-21 gHVYpd"]789[/TD]
[/TR]
[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]qwe[/TD]
[TD="class: yklcuq-21 gHVYpd"]wer[/TD]
[TD="class: yklcuq-21 gHVYpd"]ert[/TD]
[TD="class: yklcuq-21 gHVYpd"]rty[/TD]
[/TR]
</tbody>[/TABLE]
[FONT=&quot]- That is, basically, extract text following each common of "20:", "23B:" "32A" & "50K", and organize them to columns.[/FONT]

  • First of all, should I figure out a way to combine rows between the common texts "====Starting details=====" & "=====Ending details====="? It would become something like this:
[TABLE="class: yklcuq-19 cUmOil"]
<thead style="margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;">[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TH="class: yklcuq-25 kFFvu, align: center"]20: abc 23B: 321 32A: 456 50K: 789[/TH]
[/TR]
</thead><tbody style="margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;"></tbody>[/TABLE]
[FONT=&quot]2) Once step 1 is solved, I can figure out a way to extract text between 20:/23B:/32A:/50K:, and place it on different columns?[/FONT]
[FONT=&quot]
[/FONT]

[FONT=&quot]Please let me know if this is feasible? What formulas/tools on power query should I utilize?[/FONT]
[FONT=&quot]
[/FONT]

[FONT=&quot]Open to any ideas.[/FONT]
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Is that what you want?

done with PowerQuery (Get&Transform)
btw. this is not vba

[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td]SOURCE[/td][td][/td][td]RESULT[/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#5B9BD5]Column1[/td][td][/td][td=bgcolor:#70AD47]20:[/td][td=bgcolor:#70AD47]23B:[/td][td=bgcolor:#70AD47]32A:[/td][td=bgcolor:#70AD47]50K:[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]====Starting details=====[/td][td][/td][td=bgcolor:#E2EFDA]abc[/td][td=bgcolor:#E2EFDA]def[/td][td=bgcolor:#E2EFDA]ghk[/td][td=bgcolor:#E2EFDA]lmn[/td][/tr]

[tr=bgcolor:#FFFFFF][td]20: abc[/td][td][/td][td]123[/td][td]321[/td][td]456[/td][td]789[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]23B: def[/td][td][/td][td=bgcolor:#E2EFDA]qwe[/td][td=bgcolor:#E2EFDA]wer[/td][td=bgcolor:#E2EFDA]ert[/td][td=bgcolor:#E2EFDA]rty[/td][/tr]

[tr=bgcolor:#FFFFFF][td]32A: ghk[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]50K: lmn[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td]=====Ending details=====[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]====Starting details=====[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td]20: 123[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]23B: 321[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td]32A: 456[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]50K: 789[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td]=====Ending details=====[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]====Starting details=====[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td]20: qwe[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]23B: wer[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td]32A: ert[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]50K: rty[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td]=====Ending details=====[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[/table]


M-Code
Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Filtered Rows" = Table.SelectRows(Source, each ([Column1] <> "=====Ending details=====" and [Column1] <> "====Starting details=====")),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Filtered Rows", "Column1", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Column1.1", "Column1.2"}),
    #"Grouped Rows" = Table.Group(#"Split Column by Delimiter", {"Column1.1"}, {{"Count", each _, type table}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.Column([Count],"Column1.2")),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Extracted Values", "Custom", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Custom.1", "Custom.2", "Custom.3"}),
    #"Removed Columns" = Table.RemoveColumns(#"Split Column by Delimiter1",{"Count"}),
    #"Transposed Table" = Table.Transpose(#"Removed Columns"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true])
in
    #"Promoted Headers"[/SIZE]
 
Upvote 0
I know you mentioned Power Query and you have a suggestion for that, but in case it is of interest to you, following are suggestions for vba and formulas to do the job assuming the data is uniform like your samples.

1) VBA
(Assuming data in col A starting at row 1, & results into columns B:E)
Code:
Sub Rearrange()
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, k As Long
  
  a = Range("A1", Range("A" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To UBound(a), 1 To 4)
  For i = 1 To UBound(a)
    If a(i, 1) Like "====S*" Then
      k = k + 1
      For j = 1 To 4
        b(k, j) = Split(a(i + j, 1), ": ", 1)(1)
      Next j
      i = i + 5
    End If
  Next i
  Range("B2:E2").Resize(k).Value = b
  Range("B1:E1").Value = Array("'20:", "23B:", "32A:", "50K:")
End Sub

2) Formula, copied across and down.

Excel Workbook
ABCDE
1====Starting details=====20:23B:32A:50K:
220: abcabcdefghklmn
323B: def123321456789
432A: ghkqwewerertrty
550K: lmn
6=====Ending details=====
7====Starting details=====
820: 123
923B: 321
1032A: 456
1150K: 789
12=====Ending details=====
13====Starting details=====
1420: qwe
1523B: wer
1632A: ert
1750K: rty
18=====Ending details=====
Sheet1
 
Upvote 0

Forum statistics

Threads
1,224,832
Messages
6,181,235
Members
453,026
Latest member
cknader

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