Macro Needed for Pivot Data Info.

garypea123

Board Regular
Joined
Mar 16, 2020
Messages
221
Office Version
  1. 365
Platform
  1. Windows
Good Afternoon All,

Apologies as I cannot to Xl2BB from computer. I am not sure how to word this but I am trying to create a data table so I can do some Pivot Table (Possible Power Pivots)

The Raw Data format is not great to pivot as I need it more in columns

An example below is the raw data (simplified) and is on say "Sheet 1"

Pivot Raw.PNG


What I believe I need to do is to create a macro which will do the following in "Sheet 2" (Lets say "B3")

- Transpose data from D:P (This will always be 13 entries as I look at a 13 week period)
- I then need Column B and C to copy another 12 times to match with the data.
- The would be more than 3 rows of data in general. Columns will always be the same format but number of rows will change each week potentially)

An example of how it should look:

Pivot Conclusion.PNG
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Easy just use power query to transpose the info for you

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", Int64.Type}, {"Column4", Int64.Type}, {"Column5", Int64.Type}, {"Column6", Int64.Type}, {"Column7", Int64.Type}, {"Column8", Int64.Type}, {"Column9", Int64.Type}, {"Column10", Int64.Type}, {"Column11", Int64.Type}, {"Column12", Int64.Type}, {"Column13", Int64.Type}, {"Column14", Int64.Type}, {"Column15", Int64.Type}}),
    #"Unpivoted Only Selected Columns" = Table.Unpivot(#"Changed Type", {"Column3", "Column4", "Column5", "Column6", "Column7", "Column8", "Column9", "Column10", "Column11", "Column12", "Column13", "Column14", "Column15"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Only Selected Columns",{"Attribute"})
in
    #"Removed Columns"
Code:
Book1
BCDEFGHIJKLMNOP
2
3Column1Column2Column3Column4Column5Column6Column7Column8Column9Column10Column11Column12Column13Column14Column15
4GaryJones12345678910111213
5Tom Smith13121110987654321
6Phil Pott6666666666666
7
8Column1Column2Value
9GaryJones1
10GaryJones2
11GaryJones3
12GaryJones4
13GaryJones5
14GaryJones6
15GaryJones7
16GaryJones8
17GaryJones9
18GaryJones10
19GaryJones11
20GaryJones12
Sheet1
 
Upvote 1
Fabulous - I will take a look at this tomorrow.

I assumed this must be quite common and a simple way...Will let you know the outcode.
 
Upvote 0

If you unsure about PQ there is some info abour Pq with links supplied by alansidman in this thread​

 
Upvote 0
Another option with a formula
Fluff.xlsm
ABCDEFGHIJKLMNO
1
2Column1Column2Column3Column4Column5Column6Column7Column8Column9Column10Column11Column12Column13Column14Column15
3GaryJones12345678910111213
4Tom Smith13121110987654321
5Phil Pott6666666666666
6
7Column1Column2Value
8GaryJones1
9GaryJones2
10GaryJones3
11GaryJones4
12GaryJones5
13GaryJones6
14GaryJones7
15GaryJones8
16GaryJones9
17GaryJones10
18GaryJones11
19GaryJones12
20GaryJones13
21Tom Smith13
22Tom Smith12
23Tom Smith11
24Tom Smith10
25Tom Smith9
26Tom Smith8
27Tom Smith7
28Tom Smith6
29Tom Smith5
30Tom Smith4
31Tom Smith3
32Tom Smith2
33Tom Smith1
34Phil Pott6
35Phil Pott6
36Phil Pott6
37Phil Pott6
38Phil Pott6
39Phil Pott6
40Phil Pott6
41Phil Pott6
42Phil Pott6
43Phil Pott6
44Phil Pott6
45Phil Pott6
46Phil Pott6
Master
Cell Formulas
RangeFormula
A8:C46A8=LET(s,SEQUENCE(,13),HSTACK(TOCOL(IF(s,A3:A5)),TOCOL(IF(s,B3:B5)),TOCOL(C3:O5)))
Dynamic array formulas.
 
Upvote 1
Solution
Thank you guys - I need to do some training on power pivotting so I have some knowledge regarding this. (Thank you for the links)

Fluff, as usual your formula is exactly what I need for now (however, I do need to make an adventure into power queries etc)

:)
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,110
Messages
6,123,143
Members
449,098
Latest member
Doanvanhieu

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