Macro to Reformat/transpose data into table style

ANTONIO1981

Board Regular
Joined
Apr 21, 2014
Messages
162
Hi All


the attached file contains 2 tabs employee table macro.xlsx - Google Drive

1. assumptions

The user will populate the data in the yellow area, please take into account that the number of rows will increase substantially

2. final_results

the macro needs to take the data from tab assumptions and combine it in order to create the data shown in tab "final_results"


thanks in advance
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG10Aug36
[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 = Sheets("assumptions").Range("A1").CurrentRegion.Resize(, 17)
ReDim nray(1 To UBound(Ray, 1) * UBound(Ray, 2) + 1, 1 To 6)
c = 1
 nray(c, 1) = Ray(1, 1)
 nray(c, 2) = Ray(1, 2)
 nray(c, 3) = Ray(1, 3)
 nray(c, 4) = Ray(1, 4)
 nray(c, 5) = "Date"
 nray(c, 6) = "Amount"
[COLOR="Navy"]For[/COLOR] n = 2 To UBound(Ray, 1)
     [COLOR="Navy"]For[/COLOR] Ac = 5 To UBound(Ray, 2)
        c = c + 1
        nray(c, 1) = Ray(n, 1)
        nray(c, 2) = Ray(n, 2)
        nray(c, 3) = Format(Ray(n, 3), "mmm_yy")
        nray(c, 4) = Ray(n, 4)
        [COLOR="Navy"]If[/COLOR] IsDate(Ray(1, Ac)) [COLOR="Navy"]Then[/COLOR]
                nray(c, 5) = Format(Ray(1, Ac), "mmm_yy")
        [COLOR="Navy"]Else[/COLOR]
                nray(c, 5) = Ray(1, Ac)
        [COLOR="Navy"]End[/COLOR] If
        nray(c, 6) = Format(Ray(n, Ac), "#,##0")
    [COLOR="Navy"]Next[/COLOR] Ac
[COLOR="Navy"]Next[/COLOR] n
Sheets("final_results").Range("A1").Resize(c, 6) = nray
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
HI mICK


almost perfect

your code gives

Jan_18Feb_18Mar_18Apr_18May_18Jun_18Jul_18Aug_18Sep_18Oct_18Nov_18Dec_18


<tbody>
</tbody>

i need the code to be this

01/01/201801/02/201801/03/201801/04/201801/05/201801/06/201801/07/201801/08/201801/09/201801/10/201801/11/201801/12/2018

<tbody>
</tbody>


( i had format it as mmm-yy perhaps has confused you, sorry...)


thanks in advance
AC
 
Last edited:
Upvote 0
Try changing the line below:-
NB:- I should reformat the Resuts sheet to "General" before running the code !!!
Code:
If IsDate(Ray(1, Ac)) Then
                nray(c, 5) =[B][COLOR=#B22222] CDate(Ray(1, Ac))[/COLOR][/B]
        Else
                nray(c, 5) = Ray(1, Ac)
        End If
 
Upvote 0

Forum statistics

Threads
1,215,214
Messages
6,123,664
Members
449,114
Latest member
aides

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