Timespread data transpose

eschwanz

New Member
Joined
Jun 7, 2012
Messages
6
Hello,

I am looking for some assistance in writing a macro to transpose timespread data that is coming out of a program that I use. I need to be able to make a calculation on the data, then put it back into a pivot table to spread it again by period. I only need help getting the data from timespread to data table. See example below. The columns 1 and 2 need to be repeated for every period. The periods, will be changing every time i run the report.

Thank you for your help.

From this
ProjectResourceField01-Dec01-Jan01-Feb01-Mar01-Apr01-May01-Jun
Job AResource 1Hours20202020202020
Job AResource 2Hours 30303030
Job BResource 3Hours 2020202020
Job CResource 4Hours 5050505050
Job CResource 5Hours1010101010
Job BResource 6Hours 303030303030

<colgroup><col><col><col><col><col><col span="4"><col></colgroup><tbody>
</tbody>


Into this
ProjectResourcePeriodHours
Job AResource 101-Dec20
Job AResource 101-Jan20
Job AResource 101-Feb20
Job AResource 101-Mar20
Job AResource 101-Apr20
Job AResource 101-May20
Job AResource 101-Jun20
Job AResource 201-Dec
Job AResource 201-Jan30
Job AResource 201-Feb30
Job AResource 201-Mar30
Job AResource 201-Apr30
Job AResource 201-May
Job AResource 201-Jun
Job BResource 301-Dec
Job BResource 301-Jan
Job BResource 301-Feb20
Job BResource 301-Mar20
Job BResource 301-Apr20
Job BResource 301-May20
Job BResource 301-Jun20
Job CResource 401-Dec
Job CResource 401-Jan50
Job CResource 401-Feb50
Job CResource 401-Mar50
Job CResource 401-Apr50
Job CResource 401-May50
Job CResource 401-Jun
Job CResource 501-Dec10
Job CResource 501-Jan10
Job CResource 501-Feb10
Job CResource 501-Mar10
Job CResource 501-Apr10
Job CResource 501-May
Job CResource 501-Jun
Job BResource 601-Dec
Job BResource 601-Jan30
Job BResource 601-Feb30
Job BResource 601-Mar30
Job BResource 601-Apr30
Job BResource 601-May30
Job BResource 601-Jun30

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Try this for results on sheet2.
Code:
[COLOR="Navy"]Sub[/COLOR] MG07Dec23
[COLOR="Navy"]Dim[/COLOR] Ray [COLOR="Navy"]As[/COLOR] Variant, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
Ray = ActiveSheet.Cells(1).CurrentRegion
ReDim nray(1 To UBound(Ray, 1) * UBound(Ray, 2), 1 To 4)
nray(1, 1) = "project": nray(1, 2) = "Resource"
nray(1, 3) = "Periord": nray(1, 4) = "Hour"
c = 1
[COLOR="Navy"]For[/COLOR] n = 2 To UBound(Ray, 1)
    [COLOR="Navy"]For[/COLOR] Ac = 4 To UBound(Ray, 2)
        c = c + 1
        nray(c, 1) = Ray(n, 1): nray(c, 2) = Ray(n, 2)
        nray(c, 3) = Format(Ray(1, Ac), "dd-mmm"): nray(c, 4) = Ray(n, Ac)
    [COLOR="Navy"]Next[/COLOR] Ac
[COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]With[/COLOR] Sheets("Sheet2").Range("A1").Resize(c, 4)
    .Value = nray
    .Borders.Weight = 2
    .Columns.AutoFit
 [COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Thanks Mick. This worked perfectly. In the last lines, I am having this feed into a pivot table, what do i need to have the data on sheet2 formatted as a table or dumped into a table? So i dont have to change the data source of the pivot table to captured new rows in the original data set.
 
Last edited:
Upvote 0
If you change the last few lines as below it should convert the results data in sheet2 to a "Table".
Code:
With Sheets("Sheet2").Range("A1").Resize(c, 4)
   .Value = nray
   .Columns.AutoFit
End With
Sheets("Sheet2").ListObjects.Add(xlSrcRange, Sheets("Sheet2").Range("A1").Resize(c, 4), , xlYes).Name = "MyTable"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,949
Messages
6,127,877
Members
449,410
Latest member
adunn_23

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