transpose data with same value in column A by date order

rmx8000

New Member
Joined
Mar 22, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm trying to think of a way to use VBA to transpose data with the same value in column A by sequential date order.

e.g starting with this:

CARdatecostref
VW
01/02/2013​
20​
ax1
FORD
01/01/2018​
22​
bx2
VW
01/08/2014​
21​
cx3
FORD
01/08/2017​
25​
cd3
AUDI
05/02/2016​
13​
cf4
AUDI
05/02/2020​
18​
cf5
VW
01/10/2016​
19​
cg6
AUDI
01/02/2014​
16​
gh4

The output I would like is this:

date1cost1ref1date2cost2ref2date3cost3ref3
AUDI
01/02/2014​
16​
gh4
05/02/2016​
13​
cf4
05/02/2020​
18​
cf5
FORD
01/08/2016​
20​
df4
01/08/2017​
25​
cd3
VW
01/02/2013​
20​
ax1
01/08/2014​
21​
cx3
01/10/2016​
19​
cg6

Does anyone know a way to do this in excel / VBA?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Assuming the table below is in Cells A1:D9, you can use the following function:

CARdatecostref
VW1/2/201320ax1
FORD1/1/201822bx2
VW1/8/201421cx3
FORD1/8/201725cd3
AUDI5/2/201613cf4
AUDI5/2/202018cf5
VW1/10/201619cg6
AUDI1/2/201416gh



Excel Formula:
=VSTACK(HSTACK("CAR",LET(CarBrands,A2:A9,UniqueBrand,SORT(UNIQUE(CarBrands)),ColumnsNames,{"date","cost","ref"},ColumnCount,LAMBDA(values,num_repeat,
XLOOKUP(SEQUENCE(SUM(num_repeat)),VSTACK(1,SCAN(1,num_repeat,LAMBDA(a,b,a+b))),VSTACK(values,""),,-1))(TRANSPOSE(ColumnsNames),SEQUENCE(COUNTA(UniqueBrand),1,MAX(COUNTIF(CarBrands,UniqueBrand)),0)),SortValue,LET(Val,MOD(SEQUENCE(COUNTA(ColumnCount),1,1,1),3),IF(Val=0,3,Val)),TRANSPOSE(SORTBY(ColumnCount,SortValue))&TRANSPOSE(SORT(SortValue)))),HSTACK(SORT(UNIQUE(A2:A9)),LET(FinalTable,LET(MainTable,LET(SortedDates,SORTBY(A2:D9,B2:B9),SORTBY(SortedDates,INDEX(SortedDates,,1))),DROP(IFERROR(REDUCE("",BYROW(SORT(UNIQUE(A2:A9)),LAMBDA(r,TEXTJOIN(", ",TRUE,FILTER(DROP(MainTable,,1),INDEX(MainTable,,1)=r)))),LAMBDA(x,y,VSTACK(x,TEXTSPLIT(y,", ")))),""),1)),IF(LEN(FinalTable)=5,TEXT(FinalTable,"mm/dd/yyyy"),FinalTable))))
 
Upvote 0
Solution
wow, that's pretty complex, but it works a treat.

Thank you very much for your help.
 
Upvote 0
Hi & welcome to MrExcel.
Another (slightly shorter) formula
Fluff.xlsm
ABCDEFGHIJKLMNO
1CARdatecostref
2VW01/02/201320ax1AUDI01/02/201416gh05/02/201613cf405/02/202018cf5
3FORD01/01/201822bx2FORD01/08/201725cd301/01/201822bx2
4VW01/08/201421cx3VW01/02/201320ax101/08/201421cx301/10/201619cg6
5FORD01/08/201725cd3
6AUDI05/02/201613cf4
7AUDI05/02/202018cf5
8VW01/10/201619cg6
9AUDI01/02/201416gh
Sheet6
Cell Formulas
RangeFormula
F2:O4F2=LET(u,SORT(UNIQUE(FILTER(A2:A100,A2:A100<>""))),m,MAX(COUNTIFS(A:A,u)),DROP(REDUCE("",u,LAMBDA(x,y,VSTACK(x,HSTACK(y,EXPAND(TOROW(SORT(FILTER(B2:D100,A2:A100=y))),,m*3,""))))),1))
Dynamic array formulas.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,182
Members
452,615
Latest member
bogeys2birdies

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