Transpose data in excel

khaledshahin

New Member
Joined
Sep 18, 2024
Messages
2
Office Version
  1. 365
Platform
  1. MacOS
Hi,

I need your help to change the format of Table#1 to Table#2

Table#1 (raw data)
Project NameStaff Name
Project 1John
Project 1Jess
Project 1Jack
Project 2Ann
Project 2Jess
Project 2John
Project 2Pete

Table#2 (Required format)
Project NameStaff Name 1Staff Name 2Staff Name 3Staff Name 4
Project 1JohnJessJack
Project 2AnnJessJohnPete

Thank you in advance
KS
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi & welcome to MrExcel.
How about
Fluff.xlsm
ABCDEFGH
1Project NameStaff NameProject NameStaff Name 1Staff Name 2Staff Name 3Staff Name 4
2Project 1JohnProject 1JohnJessJack
3Project 1JessProject 2AnnJessJohnPete
4Project 1Jack
5Project 2Ann
6Project 2Jess
7Project 2John
8Project 2Pete
9
Data
Cell Formulas
RangeFormula
D1:H3D1=LET(u,UNIQUE(FILTER(A2:A100,A2:A100<>"")),m,MAX(COUNTIFS(A:A,u)),REDUCE(HSTACK(A1,B1&" "&SEQUENCE(,m)),u,LAMBDA(x,y,VSTACK(x,HSTACK(y,EXPAND(TOROW(FILTER(B2:B100,A2:A100=y)),,m,""))))))
Dynamic array formulas.
 
Upvote 0
An alternative with Power Query aka Get and Transform Data and found on the Data Tab

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"Project Name"}, {{"Count", each _, type table [Project Name=text, Staff Name=text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count], "Index",1,1)),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Project Name", "Staff Name", "Index"}, {"Project Name", "Staff Name", "Index"}),
    #"Added Prefix" = Table.TransformColumns(#"Expanded Custom", {{"Index", each "Staff Name " & Text.From(_, "en-US"), type text}}),
    #"Pivoted Column" = Table.Pivot(#"Added Prefix", List.Distinct(#"Added Prefix"[Index]), "Index", "Staff Name")
in
    #"Pivoted Column"

Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

- Follow this link to learn how to install Power Query in Excel 2010 / 2013.

- Follow this link for an introduction to Power Query functionality.

- Follow this link for a video which demonstrates how to use Power Query code provided.
 
Upvote 0
Assumes Columns 3 and higher are free to use. Result will be like Fluff's picture
Code:
Sub Maybe_So()
Dim c As Range, ac As Range, i As Long
Set ac = ActiveCell
Application.ScreenUpdating = False
    Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row).AdvancedFilter Action:=xlFilterCopy, _
    CopyToRange:=Cells(1, 4), Unique:=True
        For Each c In Range("D2:D" & Cells(Rows.Count, "D").End(xlUp).Row)
            With Columns(1)
                .Range(.Find(c.Value, , , 1, , 1), .Find(c.Value, , , 1, , 2)).Offset(, 1).Copy
                c.Offset(, 1).PasteSpecial Transpose:=True
            End With
        Next c
    ac.Select
For i = 5 To Cells(1, 4).CurrentRegion.Columns.Count + 3
Cells(1, i).Value = "Staff Name " & i - 4
Next i
ac.Select
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,534
Messages
6,160,385
Members
451,645
Latest member
hglymph

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