Listing values in an array in chronological order

ATSJ

Board Regular
Joined
Dec 7, 2010
Messages
58
Currently I have a column of dates (A) and a column of numerical values (B).

[TABLE="width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]1/1/19[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/2/19[/TD]
[TD]8[/TD]
[/TR]
[TR]
[TD]1/3/19[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]1/4/19[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/5/19[/TD]
[TD]7[/TD]
[/TR]
</tbody>[/TABLE]


The dates are listed in ascending order in col A. The values are listed in col B but not every date has a value.
In a separate column (E) I want to list the values in B in a list without the blanks, in other words just a list of the numerical values. I'm using the following array formula to do that in column E.

{=IFERROR(INDEX(B$10:B$1000,SMALL(IF(B$10:B$1000<>"",ROW(B$10:B$1000)-ROW(B$10)+1),ROWS(B$10:B10))),"")}

<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; white-space: inherit;"></code>The formula looks down col. B starting at row 10 and whenever it finds a value, drops it in col. E and it works perfectly. The values are extracted in chronological order (and if I switch out SMALL for LARGE it reverses the list so the most recent are at the top).

[TABLE="width: 500"]
<tbody>[TR]
[TD]E[/TD]
[/TR]
[TR]
[TD]8[/TD]
[/TR]
[TR]
[TD]3[/TD]
[/TR]
[TR]
[TD]7[/TD]
[/TR]
</tbody>[/TABLE]


However, I want to add a second column of numerical values in col. C. My question is - how can I adapt my current formula so it looks in both columns B and C rather than just B and continues to list them chronologically (in other words for each date, it looks in B and C before proceeding to the next date)?

[TABLE="width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD]1/1/19[/TD]
[TD][/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]1/2/19[/TD]
[TD]2[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD]1/3/19[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/4/19[/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Output

[TABLE="width: 500"]
<tbody>[TR]
[TD]E[/TD]
[/TR]
[TR]
[TD]3[/TD]
[/TR]
[TR]
[TD]2[/TD]
[/TR]
[TR]
[TD]7[/TD]
[/TR]
[TR]
[TD]1[/TD]
[/TR]
</tbody>[/TABLE]


I've tried adapting the formula to include an array,

B$10:C$1000

<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; white-space: inherit;"></code>for example, but without success because in this instance (where there is more than one column in the array) it seems that INDEX requires a column reference that isn't in my existing formula and I haven't managed to add yet.

[FONT=&quot]INDEX (array, row_num, [col_num], [area_num])
[/FONT]

Any help would be appreciated.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
In E1, copied down to E4 :

=INDEX(($B$1:$B$4,$C$1:$C$4),AGGREGATE(15,6,ROW(A$1:A$4)/(B$1:C$4<>""),ROW(A1)),1,MOD(AGGREGATE(15,6,(ROW(A$1:A$4)*100+COLUMN(A$1:B$1))/(B$1:C$4<>""),ROW(A1)),100))

Regards
 
Upvote 0
Thank you so much. Now, say I wanted to add a third column in D, would it be a simple process to update this to incorporate an extra column?
 
Upvote 0
Should you add (a 3rd) one more column in D1:D4

The formula basically look in same, just add one column and change the range reference, then become :

=INDEX(($B$1:$B$4,$C$1:$C$4,$D$1:$D$4),AGGREGATE(15,6,ROW(A$1:A$4)/(B$1:D$4<>""),ROW(A1)),1,MOD(AGGREGATE(15,6,(ROW(A$1:A$4)*100+COLUMN(A$1:C$1))/(B$1:D$4<>""),ROW(A1)),100))

I used Index function for the working because INDEX is easy for you to understanding

However, it would be simplified by :

=INDIRECT(TEXT(AGGREGATE(15,6,ROW(A$1:A$4)*100+COLUMN(B$1:D$1)/(B$1:D$4<>""),ROW(A1)),"R0C00"),0)

Regards
Bosco
 
Upvote 0
Thank you so much. Now, say I wanted to add a third column in D, would it be a simple process to update this to incorporate an extra column?
Just a word of warning: The suggestions made so far will return incorrect results if rows are subsequently added or deleted above the data. The formulas of course can be made robust against that but I'll leave that for bosco_yip if that is a concern for you.

Also, if using the INDIRECT formula option be aware that INDIRECT is a volatile function so can slow your sheet down if you have a lot of those formulas in it.

If you have Excel through Office 365 or Excel 2019 (that is, you have the TEXTJOIN function) then here is another option for you.
Leave cell F9 blank
Formula in F10 copied down as far as you might need.

Excel Workbook
ABCDEF
8Result
9
101/01/201933
111/02/20192752
121/03/20197
131/04/2019185
141
158
16
17
Chronological order
 
Last edited:
Upvote 0
Leave cell F9 blank
If this requirement in my previous suggestion is unacceptable, then here is another (longer) version that does not have that requirement.

Excel Workbook
ABCDEF
9Result
101/01/201933
111/02/20192752
121/03/20197
131/04/2019185
141
158
16
Chronological order (3)
 
Upvote 0

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

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