fastest way to tranpose this data...vba or formula

daveyc18

Well-known Member
Joined
Feb 11, 2013
Messages
707
Office Version
  1. 365
  2. 2010

so i manually have the dates in a vertical row (eg in column P, starting row 3, i have jan 96, cell p4 is feb 96, p5 is march 96, etc.) ...then i used this formula in Q3 (=OFFSET($B$3,0,ROW()-3,1,1)) and dragged it down so that horizontal data is now vertifcal

this is too manual since for the year 1997, i need to manually change the formula again (in Q15, I have =OFFSET($B$4,0,ROW()-15,1,1))

perhaps a macro that loops would be better? e.g., copy b3:m3 , paste to q3 (year 1996)...then copy b4:m4, paste to q15 (year 1997) ...my VBA isnt good enough to write this..help!
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Does TRANSPOSE produce the desired result? Here's just a snippet with the formula:
historical-rate-sheet---Janaury-2021.xlsx
PQRSTUVW
2Year1996199719981999200020012002
3January8.02%7.14%6.90%6.72%8.34%7.58%6.62%
4February7.79%7.12%6.84%6.79%8.43%7.52%6.59%
5March8.16%7.06%6.84%7.03%8.24%7.19%6.80%
6April8.48%7.56%6.79%6.71%8.23%7.22%7.00%
7May8.47%7.46%6.92%6.99%8.50%7.38%7.00%
8June8.48%7.22%6.90%7.35%8.34%7.47%6.98%
9July8.48%6.98%6.90%7.42%8.18%7.46%6.90%
10August8.07%7.00%7.08%7.80%8.08%7.39%6.61%
11September7.94%6.96%7.32%7.67%8.08%7.03%6.49%
12October7.50%6.73%6.73%7.90%8.08%6.74%6.50%
13November7.01%6.69%6.94%8.13%8.04%6.51%6.47%
14December6.94%6.90%6.69%8.13%7.81%6.64%6.39%
15Average7.95%7.07%6.90%7.39%8.20%7.18%6.70%
Table 1
Cell Formulas
RangeFormula
P2:AR15P2=TRANSPOSE(A2:N30)
Dynamic array formulas.
 
Upvote 0
Does TRANSPOSE produce the desired result? Here's just a snippet with the formula:
historical-rate-sheet---Janaury-2021.xlsx
PQRSTUVW
2Year1996199719981999200020012002
3January8.02%7.14%6.90%6.72%8.34%7.58%6.62%
4February7.79%7.12%6.84%6.79%8.43%7.52%6.59%
5March8.16%7.06%6.84%7.03%8.24%7.19%6.80%
6April8.48%7.56%6.79%6.71%8.23%7.22%7.00%
7May8.47%7.46%6.92%6.99%8.50%7.38%7.00%
8June8.48%7.22%6.90%7.35%8.34%7.47%6.98%
9July8.48%6.98%6.90%7.42%8.18%7.46%6.90%
10August8.07%7.00%7.08%7.80%8.08%7.39%6.61%
11September7.94%6.96%7.32%7.67%8.08%7.03%6.49%
12October7.50%6.73%6.73%7.90%8.08%6.74%6.50%
13November7.01%6.69%6.94%8.13%8.04%6.51%6.47%
14December6.94%6.90%6.69%8.13%7.81%6.64%6.39%
15Average7.95%7.07%6.90%7.39%8.20%7.18%6.70%
Table 1
Cell Formulas
RangeFormula
P2:AR15P2=TRANSPOSE(A2:N30)
Dynamic array formulas.


I'm trying to make the data like this so I can graph it (x axis has month and hear and y axis has rates)

pls see columns T and U in revised file attached

 
Upvote 0
I see...are you familiar with Power Query? Your table can be fed into PQ and transformed in a few steps to produce something like this...
historical-rate-sheet---Janaury-2021 - revised.xlsx
AB
1DateRate
21/1/19960.0802
32/1/19960.0779
43/1/19960.0816
54/1/19960.0848
65/1/19960.0847
76/1/19960.0848
87/1/19960.0848
98/1/19960.0807
109/1/19960.0794
1110/1/19960.075
1211/1/19960.0701
1312/1/19960.0694
141/1/19970.0714
152/1/19970.0712
163/1/19970.0706
174/1/19970.0756
185/1/19970.0746
196/1/19970.0722
207/1/19970.0698
218/1/19970.07
229/1/19970.0696
2310/1/19970.0673
2411/1/19970.0669
2512/1/19970.069
261/1/19980.069
272/1/19980.0684
283/1/19980.0684
294/1/19980.0679
305/1/19980.0692
316/1/19980.069
327/1/19980.069
338/1/19980.0708
349/1/19980.0732
3510/1/19980.0673
3611/1/19980.0694
3712/1/19980.0669
Table2

Here is the M-code I used:
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"January", type number}, {"February", type number}, {"March", type number}, {"April", type number}, {"May", type number}, {"June", type number}, {"July", type number}, {"August", type number}, {"September", type number}, {"October", type number}, {"November", type number}, {"December", type number}}),
    #"Demoted Headers" = Table.DemoteHeaders(#"Changed Type"),
    #"Transposed Table1" = Table.Transpose(#"Demoted Headers"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table1", [PromoteAllScalars=true]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Promoted Headers", {"Year"}, "Attribute", "Value"),
    #"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Date", each [Year]&"-"&[Attribute]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Year", "Attribute"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Date", "Value"}),
    #"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Value", "Rate"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Date", type date}, {"Rate", Percentage.Type}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type1",{{"Date", Order.Ascending}})
in
    #"Sorted Rows"
Table2 is what Excel automatically named your upper table...I left it. The results of this transformation were loaded from PQ onto worksheet [Table2]. I recycled the same M-code and operated on your lower table (Table4) and those results are shown on a sheet of the same name...here...
 
Upvote 0
I see...are you familiar with Power Query? Your table can be fed into PQ and transformed in a few steps to produce something like this...
historical-rate-sheet---Janaury-2021 - revised.xlsx
AB
1DateRate
21/1/19960.0802
32/1/19960.0779
43/1/19960.0816
54/1/19960.0848
65/1/19960.0847
76/1/19960.0848
87/1/19960.0848
98/1/19960.0807
109/1/19960.0794
1110/1/19960.075
1211/1/19960.0701
1312/1/19960.0694
141/1/19970.0714
152/1/19970.0712
163/1/19970.0706
174/1/19970.0756
185/1/19970.0746
196/1/19970.0722
207/1/19970.0698
218/1/19970.07
229/1/19970.0696
2310/1/19970.0673
2411/1/19970.0669
2512/1/19970.069
261/1/19980.069
272/1/19980.0684
283/1/19980.0684
294/1/19980.0679
305/1/19980.0692
316/1/19980.069
327/1/19980.069
338/1/19980.0708
349/1/19980.0732
3510/1/19980.0673
3611/1/19980.0694
3712/1/19980.0669
Table2

Here is the M-code I used:
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"January", type number}, {"February", type number}, {"March", type number}, {"April", type number}, {"May", type number}, {"June", type number}, {"July", type number}, {"August", type number}, {"September", type number}, {"October", type number}, {"November", type number}, {"December", type number}}),
    #"Demoted Headers" = Table.DemoteHeaders(#"Changed Type"),
    #"Transposed Table1" = Table.Transpose(#"Demoted Headers"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table1", [PromoteAllScalars=true]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Promoted Headers", {"Year"}, "Attribute", "Value"),
    #"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Date", each [Year]&"-"&[Attribute]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Year", "Attribute"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Date", "Value"}),
    #"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Value", "Rate"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Date", type date}, {"Rate", Percentage.Type}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type1",{{"Date", Order.Ascending}})
in
    #"Sorted Rows"
Table2 is what Excel automatically named your upper table...I left it. The results of this transformation were loaded from PQ onto worksheet [Table2]. I recycled the same M-code and operated on your lower table (Table4) and those results are shown on a sheet of the same name...here...
Tks for your effort ...I'm not familiar with power query but I'll take a look
 
Upvote 0
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

Forum statistics

Threads
1,214,918
Messages
6,122,257
Members
449,075
Latest member
staticfluids

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