You can do the transposing without any macro:
The direct way for your first step would be to use the TRANSPOSE
function, i.e. select a range that is 365rowsx24cols and enter =TRANSPOSE(B4:NB27)
and press Ctrl+Shift+Enter.
However, I'd recommend to address problem 1 and 2 in a slightly different manner: Translate your data to a list, i.e. a table with 365x24 rows x 3 columns: Date, Hour, Value. This table can then be easily be used as the source for a pivot table!
To do so, you could either use two helper columns - the first one starting at 1 and increasing every row by one until it's 24 then reset (In A2: 1
, in A3: =IF(A2=24,1,A2+1)
), the second starting with 1 and increasing by 1 every 24 rows (B2: 1
, B3: =IF(A3=1,B2+1,B2)
. Alternatively, you could simply use the ROW()
function (which returns you the row of the cell with the formula if no parameter is provided) to derive the number 1 to 24 with MOD(ROW(),24)-1
and the 1 to 365 with INT((ROW()-2)/24)+1
. (The +1
and -2
is to adjust for the data table starting in row 2).
Using the INDEX
function with those two parameters, you can now easily retrieve the data for the 3 columns:
Date: =INDEX($B$3:$NB$3,B2)
(or without the helper columns: =INDEX($B$3:$NB$3,INT((ROW()-2)/24)+1)
)
Hour: =INDEX($A$4:$A$27,A2)
(or =INDEX($A$4:$A$27,MOD(ROW(),24)-1)
)
Value: =INDEX($B$4:$NB$27,A2,B2)
(or =INDEX($B$4:$NB$27,MOD(ROW(),24)-1),INT((ROW()-2)/24)+1)
)
1I'm voting to close this question as off-topic because the question wasn't clear even when the image links worked (see comment on answer). The links are now broken and the OP hasn't returned in 3 yrs, so the question isn't answerable. – fixer1234 – 2016-03-02T00:38:37.050
I'm voting to close this question as off-topic because the question wasn't clear even when the image links worked (see comment on answer). The links are now broken and the OP hasn't returned in 3 yrs, so the question isn't answerable – DavidPostill – 2017-04-06T14:32:49.787
1You're dealing with two concepts here: a looping macro, and chart/graphing techniques. Split this into two questions, and show your macro so far for the first question, and your table/graph so far for the second. – mcalex – 2013-03-10T10:55:18.753
Range("AB4:AB27").Select Selection.Copy Range("B28").Select ActiveSheet.Paste Range("B4:B27").Select – Peter – 2013-03-13T15:20:22.723