Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

# Desired Format Pivot

Posted on 2013-02-04
Medium Priority
303 Views
Hello ,
Current Format shows the data structure it’s in currently.  Somehow, someway it has to be pivoted to get it in the format I need where time stamp columns transform to the rows instead.  The format I need is shown in Desired Format sheet. The fastest way to o this on 35000-40000 rows
Thanks
pivotDesired.xlsx
0
Question by:Rayne
• 4
• 3
• 3

LVL 24

Assisted Solution

Steve earned 400 total points
ID: 38852607
the following code will do exactly what is required in the example workbook

``````Sub Normalise()
Dim myRng As Range
Dim myArr()
Dim x as long
Dim y as long
Dim z as long

Set myRng = ThisWorkbook.Sheets("Current").Range("A2:CX108")
Z = 1
For x = 2 To 107
For y = 1 To 100
ReDim Preserve myArr(1 To 4, 1 To Z)
myArr(1, Z) = myRng(x, 1)
myArr(2, Z) = myRng(x, 2)
myArr(3, Z) = myRng(1, y + 2)
myArr(4, Z) = myRng(x, y + 2)
Z = Z + 1
Next y
Next x
ThisWorkbook.Sheets("desired").Range("A3:D" & Z + 1) = Application.Transpose(myArr)
End Sub
``````

If the code needs to be more "flexible" can change the code if required.
pivotDesired.xlsm
0

LVL 50

Accepted Solution

Ingeborg Hawighorst (Microsoft MVP / EE MVE) earned 1600 total points
ID: 38852633
Hello,

this can be done with a "reverse pivot", but first we need to change the source a bit:

Insert a column after column B, put a label in row 2 and in row 3 enter the formula

=A3&"-"&B3

Copy down. Now for the reverse Pivot.

1.  click a cell in the table and then use Alt - D - P to bring up the good, old Pivot Table wizard (yes, it's still there!)
2. in the first step, click "Multiple consolidation ranges" and Next
3. in Step 2a click "I will create the page fields" and Next
4. in Step 2b select the range, starting with the newly inserted column. Do not include columns A and B.  -- then click Next
5. in Step 3 select "new Worksheet" and click Finish

You will now see a pivot table. In the Pivot table field pane, drag all the fields from the Column Labels and the Row Labels areas back up into the field list. You will see the pivot table reduced to one cell with a number and a label above.

Double-click the number.

This will create a sheet with the raw data. Now you only need to split the previously concatenated columns A and B. Insert a new column between A and B and perform a Text to Columns on column A, using the "-" as the delimiter.

cheers, teylyn
0

Author Comment

ID: 38852799

Teylyn, Please check attached. This is what I got so far.
I don’t understand what to do here?-
"In the Pivot table field pane, drag all the fields from the Column Labels and the Row Labels areas back up into the field list"

Can you explain? I dragged all the three fields out of there, after which I didn’t see anything
pivotSoFar.png
0

LVL 50

Expert Comment

ID: 38852860
See the four panels at the bottom of the field list in the pivot pane? The upper right has the "Column" field in it. The lower left has the "Row" field in it. Click and drag these two items up into the field list, so that the two panes are empty and the only thing left is "Sum of Value" in the lower right hand box.

That will transform the pivot table into a one cell affair with a label. Then double click the number in the one pivot cell.
0

LVL 24

Assisted Solution

Steve earned 400 total points
ID: 38852863
Cool method Teylyn:

Rayne, all you now do is drag the row and column off the column and row label areas..
So as to just leave the "Sum Of"

Then double click the large number that is left.
This will create the same data as the macro.
Cool.

I am sure that this would be a great topic for an article. ;)
0

LVL 50

Expert Comment

ID: 38852894
>> I am sure that this would be a great topic for an article. ;)

0

LVL 24

Expert Comment

ID: 38852912
Ahha... "good old" John,

His is are some of the few books I have in actual book form, and would heartily recommend.
(that and a dictionarry, as I am sure my spelling is getting worse as I get older)

But this is a great example of returning pivot data back to normal form.
Cheers,
Steve.
0

Author Comment

ID: 38852952
Thanks Everyone for chipping in
Teylyn
All Hats off to you :)
Thanks a million
0

Author Comment

ID: 38852973
Here's the follow up question...if anyone is interested :)
0

Author Comment

ID: 38852974
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question