Tranposing many date field columns to single row entries

lewjan

New Member
Joined
Dec 4, 2020
Messages
11
Office Version
  1. 2010
Platform
  1. Windows
Hello,
Thank you in advance for assisting; much appreciated!!

I have a spreadsheet with multiple columns of environment plus date field and trying to find a way to transpose each into row.
Example:
Project A has 28 columns, each column pertains to Env + if planned or actual + start or end date
I was hoping to transpose each 28 columns into 28 rows per project.
I have over 200 projects each with 28 env-date columns.

Current:
ProjectLabPlannedStartLabActualStartLabPlannedCompleteLabActualCompleteDevPlannedStartDevActualStartDevPlannedCompleteDevActualCompleteQAPlannedStartQAActualStartQAPlannedCompleteQAActualCompleteIntPlannedStartIntActualStartIntPlannedCompleteIntActualComplete
Apples
8/1/2021​
7/30/2023​
9/30/2021​
7/30/2023​
########​
7/30/2023​
Oranges
1/16/2022​
2/27/2022​
Pears
10/3/2021​
12/30/2021​
Melons
Cherries
11/27/2022​
2/12/2023​
1/8/2023​


Transposed:
ProjectEnv-TypeDate
ApplesLabPlannedStart
ApplesLabActualStart
ApplesLabPlannedComplete
ApplesLabActualComplete
ApplesDevPlannedStart
8/1/2021​
ApplesDevActualStart
ApplesDevPlannedComplete
7/30/2023​
ApplesDevActualComplete
ApplesQAPlannedStart
9/30/2021​
ApplesQAActualStart
ApplesQAPlannedComplete
7/30/2023​
ApplesQAActualComplete
ApplesIntPlannedStart
8/31/2021​
ApplesIntActualStart
ApplesIntPlannedComplete
7/30/2023​
ApplesIntActualComplete
ApplesPreProdPlannedStart
ApplesPreProdActualStart
ApplesPreProdPlannedComplete
ApplesPreProdActualComplete
ApplesProdPlannedStart
12/31/2021​
ApplesProdActualStart
ApplesProdPlannedComplete
7/30/2023​
ApplesProdActualComplete
ApplesOptPlannedStart
ApplesOptActualStart
ApplesOptPlannedComplete
ApplesOptActualComplete
OrangesLabPlannedStart
OrangesLabActualStart
OrangesLabPlannedComplete
OrangesLabActualComplete
OrangesDevPlannedStart
OrangesDevActualStart
OrangesDevPlannedComplete
1/16/2022​
OrangesDevActualComplete
OrangesQAPlannedStart
OrangesQAActualStart
OrangesQAPlannedComplete
OrangesQAActualComplete
OrangesIntPlannedStart
OrangesIntActualStart
OrangesIntPlannedComplete
2/27/2022​
OrangesIntActualComplete
OrangesPreProdPlannedStart
OrangesPreProdActualStart
OrangesPreProdPlannedComplete
OrangesPreProdActualComplete
OrangesProdPlannedStart
OrangesProdActualStart
OrangesProdPlannedComplete
4/17/2022​
OrangesProdActualComplete
OrangesOptPlannedStart
OrangesOptActualStart
OrangesOptPlannedComplete
5/15/2022​
OrangesOptActualComplete
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Try this. Data in sheet1, results in "Transposed" sheet

VBA Code:
Sub Transposed_Data()
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, k As Long
  
  a = Sheets("Sheet1").Range("A1").CurrentRegion
  ReDim b(1 To UBound(a, 1) * UBound(a, 2), 1 To 3)
  
  For i = 2 To UBound(a, 1)
    For j = 2 To UBound(a, 2)
      k = k + 1
      b(k, 1) = a(i, 1)
      b(k, 2) = a(1, j)
      b(k, 3) = a(i, j)
    Next j
  Next i
  Sheets("Transposed").Range("A1").Resize(k, 3).Value = b
End Sub
 
Upvote 0
in Power Query starting with a table named Table1:

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Header1toEnd = List.LastN(Table.ColumnNames(Source),Table.ColumnCount(Source)-1),
    ReplaceNulls = Table.ReplaceValue(Source,null,"@#$%^&*&^%$#@",Replacer.ReplaceValue,Header1toEnd),
    UnpivotColumns = Table.UnpivotOtherColumns(ReplaceNulls, {"Project"}, "Env-Type", "Date"),
    RestoreNulls = Table.ReplaceValue(UnpivotColumns,"@#$%^&*&^%$#@",null,Replacer.ReplaceValue,{"Date"})

in
    RestoreNulls
 
Upvote 0
Try this. Data in sheet1, results in "Transposed" sheet

VBA Code:
Sub Transposed_Data()
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, k As Long
 
  a = Sheets("Sheet1").Range("A1").CurrentRegion
  ReDim b(1 To UBound(a, 1) * UBound(a, 2), 1 To 3)
 
  For i = 2 To UBound(a, 1)
    For j = 2 To UBound(a, 2)
      k = k + 1
      b(k, 1) = a(i, 1)
      b(k, 2) = a(1, j)
      b(k, 3) = a(i, j)
    Next j
  Next i
  Sheets("Transposed").Range("A1").Resize(k, 3).Value = b
End Sub
 
Upvote 0
Try this. Data in sheet1, results in "Transposed" sheet

VBA Code:
Sub Transposed_Data()
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, k As Long
 
  a = Sheets("Sheet1").Range("A1").CurrentRegion
  ReDim b(1 To UBound(a, 1) * UBound(a, 2), 1 To 3)
 
  For i = 2 To UBound(a, 1)
    For j = 2 To UBound(a, 2)
      k = k + 1
      b(k, 1) = a(i, 1)
      b(k, 2) = a(1, j)
      b(k, 3) = a(i, j)
    Next j
  Next i
  Sheets("Transposed").Range("A1").Resize(k, 3).Value = b
End Sub
Thank you so very much DanteAmor!! it works!! thank you, thank you, thank you!
 
Upvote 0
in Power Query starting with a table named Table1:

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Header1toEnd = List.LastN(Table.ColumnNames(Source),Table.ColumnCount(Source)-1),
    ReplaceNulls = Table.ReplaceValue(Source,null,"@#$%^&*&^%$#@",Replacer.ReplaceValue,Header1toEnd),
    UnpivotColumns = Table.UnpivotOtherColumns(ReplaceNulls, {"Project"}, "Env-Type", "Date"),
    RestoreNulls = Table.ReplaceValue(UnpivotColumns,"@#$%^&*&^%$#@",null,Replacer.ReplaceValue,{"Date"})

in
    RestoreNulls
T

in Power Query starting with a table named Table1:

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Header1toEnd = List.LastN(Table.ColumnNames(Source),Table.ColumnCount(Source)-1),
    ReplaceNulls = Table.ReplaceValue(Source,null,"@#$%^&*&^%$#@",Replacer.ReplaceValue,Header1toEnd),
    UnpivotColumns = Table.UnpivotOtherColumns(ReplaceNulls, {"Project"}, "Env-Type", "Date"),
    RestoreNulls = Table.ReplaceValue(UnpivotColumns,"@#$%^&*&^%$#@",null,Replacer.ReplaceValue,{"Date"})

in
    RestoreNulls
Thank you JGordon11!!
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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