'Un-pivoting' normal table/matrix

maximus510

New Member
Joined
May 16, 2022
Messages
2
Office Version
  1. 2021
Platform
  1. Windows
Hi everyone,

I have a matrix of months and years (hardcoded) which I want to list out in 1 big list, 'unpivoting' so as there are, for example below, 3 "30/04/22" listed, then 3 "31/05/22" etc etc for the whole matrix. The list would be 83 rows which sums to the matrix:-

JanFebMarAprMayJunJulAugSepOctNovDec
2022000333333331
2023333333333330
2024222222222223

30/04/2022
30/04/2022
30/04/2022
31/05/2022
31/05/2022
31/05/2022
etc

Is this possible?

Thanks
Max
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Assuming your data starts in A1 (2022 in A2, Jan in B1)

This puts the list in column P

VBA Code:
Sub jecc()
 Dim sq(), ar, j As Long, jj As Long, jjj As Long, x As Long
 ar = Cells(2, 1).CurrentRegion
 
 For j = 2 To UBound(ar)
   For jj = 2 To UBound(ar, 2)
     For jjj = 1 To ar(j, jj)
       ReDim Preserve sq(x)
        sq(x) = DateSerial(ar(j, 1), Month("1-" & ar(1, jj)) + 1, 0)
        x = x + 1
     Next
   Next
 Next
     
 Cells(2, 16).Resize(x) = Application.Transpose(sq)
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,755
Members
449,094
Latest member
dsharae57

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