Merge Data From Two Lines Into One

jdkuehne

New Member
Joined
Nov 5, 2018
Messages
8
I'm not really sure what the correct name is for what I want to do, so here's a description.

I have an Excel sheet where column A has, in some cases, the same value, but column B is always different. I want to move the secondary column B values to column C, Column D, etc. o the first instance of the value in column A. Like this...

This data set...
A
B
C
D
E
widget1
1-1
widget1
1-2
widget1
1-3
widget2
2-1
widget2
2-2
widget3
3-1
widget4
4-1
widget4
4-2
widget4
4-3

<tbody>
</tbody>


should be converted to this.
A
B
C
D
E
widget1
1-1
1-2
1-3
widget2
2-1
2-2
widget3
3-1
widget4
4-1
4-2
4-3

<tbody>
</tbody>
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
try PowerQuery

ABCDEAB.1B.2B.3
widget11-1widget11-11-21-3
widget11-2widget22-12-2
widget11-3widget33-1
widget22-1widget44-14-24-3
widget22-2
widget33-1
widget44-1
widget44-2
widget44-3

Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"A", type text}, {"B", type text}, {"C", type any}, {"D", type any}, {"E", type any}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"A"}, {{"Count", each _, type table}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "B", each Table.Column([Count],"B")),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"B", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "B", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"B.1", "B.2", "B.3"})
in
    #"Split Column by Delimiter"[/SIZE]
 
Upvote 0
Sandy,

Thank you for that. I have no idea how to use it, but now that I know it's possible, I'll figure it out.

Cheers!
 
Upvote 0
Because you posted this in the Excel Question section, and not the Power Query section, here is an Excel VBA solution:
Code:
Sub MyCombine()

    Dim r As Long
    
    Application.ScreenUpdating = False
    
'   Set first row to start on (skipping first row of data)
    r = 3
    
    Do
'       Check to see if column A equals row above it
        If Cells(r, "A") = Cells(r - 1, "A") Then
'           Copy value from column B to end of row above it
            Cells(r - 1, Columns.Count).End(xlToLeft).Offset(0, 1) = Cells(r, "B")
'           Delete row
            Rows(r).Delete
        Else
'           Move on to next row
            r = r + 1
        End If
    Loop Until Cells(r, "A") = ""
    
    Application.ScreenUpdating = True
    
End Sub
 
Last edited:
Upvote 0
Sandy,

Thank you for that. I have no idea how to use it, but now that I know it's possible, I'll figure it out.
Here is another macro that you can consider...
Code:
[table="width: 500"]
[tr]
	[td]Sub TransposeWidgets()
  Dim Ar As Range
  With Range("A2", Cells(Rows.Count, "A").End(xlUp))
    .Value = Evaluate("IF(" & .Address & "=" & .Offset(-1).Address & ",""""," & .Address & ")")
    For Each Ar In .SpecialCells(xlBlanks).Areas
      Ar(1).Offset(-1, 1).Resize(, Ar.Count + 1).NumberFormat = "@"
      Ar(1).Offset(-1, 1).Resize(, Ar.Count + 1) = Application.Transpose(Ar(1).Offset(-1, 1).Resize(Ar.Count + 1))
    Next
    .SpecialCells(xlBlanks).EntireRow.Delete
  End With
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
You are welcome!
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,289
Members
449,077
Latest member
Rkmenon

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