Split Rows to column or vlookup withTranspose columns

msvictorialc

New Member
Joined
Jul 4, 2015
Messages
4
1 workbook, 2 Tabs.
tab 1 is raw data with multiple rows and columns.

tab 2 is where I want to simplify the data, 1 Row per account with dataspreading out in columns instead of rows of partial duplicates.

tab 1
A B
1. 1234 Follow up
2. 1233. Follow up
3. 1233. Missing PW
4. 1233. Review 2/12
5. 1232. Called
6. 1231. Follow up

Tab 2 without Duplicate acct #’s
1. Acct#. Action. Action. Action
2. 1234. Follow up
3. 1233. Follow up. Missing PW Review 12/12
4. 1232. Called
5. 1231. Follow up
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Please Try below code make copy of your workbook before try this code

VBA Code:
Sub Split_Rows_To_Columns()
    Dim d As Object, c As Range
    Dim l, tmp As String, lr, lc As Long, i, j, k As Integer
    Dim DSheet As Worksheet
    Dim RSheet As Worksheet
    Application.ScreenUpdating = False
    Set DSheet = Sheets("TAB1") ' Chnage Raw Data Sheet name with yours Sheet Name
    Set RSheet = Sheets("TAB2") ' Chnage Result Sheet name with yours Sheet Name
    DSheet.Select
    lr = Range("A" & Rows.Count).End(xlUp).Row
    Set d = CreateObject("scripting.dictionary")
    For Each c In Range("A2:A" & lr)
        tmp = Trim(c.Value)
        If Len(tmp) > 0 Then d(tmp) = d(tmp) + 1
    Next c
    j = RSheet.Range("A" & Rows.Count).End(xlUp).Row + 1
    RSheet.Cells(1, 1).Value = "Act"
    For Each l In d.keys
        k = 1
        RSheet.Cells(j, k).Value = l
        For i = 2 To lr
            If Cells(i, 1).Value & "A" = l & "A" Then
                If Application.WorksheetFunction.CountIf(RSheet.Range("A" & j, "XFD" & j), Cells(i, 2).Value) = 0 Then
                    RSheet.Cells(j, k + 1).Value = Cells(i, 2).Value
                    RSheet.Cells(1, k + 1).Value = "Action"
                    k = k + 1
                End If
            End If
        Next
    j = j + 1
    Next
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
another way with Power Query (Get&Transform)
Acct#ActionAcct#Action
1234Follow up1234Follow up
1233Follow up1233Follow up, Missing PW, Review 2/12
1233Missing PW1232Called
1233Review 2/121231Follow up
1232Called
1231Follow up

Code:
// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Group = Table.Group(Source, {"Acct#"}, {{"Count", each _, type table}}),
    List = Table.AddColumn(Group, "Action", each Table.Column([Count],"Action")),
    Extract = Table.TransformColumns(List, {"Action", each Text.Combine(List.Transform(_, Text.From), ", "), type text})
in
    Extract

or

Acct#ActionAcct#Action.1Action.2Action.3
1234Follow up1234Follow up
1233Follow up1233Follow upMissing PWReview 2/12
1233Missing PW1232Called
1233Review 2/121231Follow up
1232Called
1231Follow up

Code:
// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Group = Table.Group(Source, {"Acct#"}, {{"Count", each _, type table}}),
    List = Table.AddColumn(Group, "Action", each Table.Column([Count],"Action")),
    Extract = Table.TransformColumns(List, {"Action", each Text.Combine(List.Transform(_, Text.From), ", "), type text}),
    Split = Table.SplitColumn(Extract, "Action", Splitter.SplitTextByDelimiter(", ", QuoteStyle.Csv), {"Action.1", "Action.2", "Action.3"})
in
    Split
 
Upvote 0
or more flexible for the second case
Code:
// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Group = Table.Group(Source, {"Acct#"}, {{"Count", each _, type table}}),
    List = Table.AddColumn(Group, "Action", each Table.Column([Count],"Action")),
    Extract = Table.TransformColumns(List, {"Action", each Text.Combine(List.Transform(_, Text.From), ", "), type text}),
    MaxCount = List.Max(Table.AddColumn(Extract, "SCount", each List.Count(Text.Split([Action],",")))[SCount]),
    Split = Table.SplitColumn(Extract, "Action", Splitter.SplitTextByDelimiter(", "), MaxCount)
in
    Split
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,876
Members
449,056
Latest member
ruhulaminappu

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