'Polyfill for Excel HSTACK and VSTACK array functions

Microsoft has announced many new array functions (https://techcommunity.microsoft.com/t5/excel-blog/announcing-new-text-and-array-functions/ba-p/3186066), including HSTACK and VSTACK, which combine several arrays into one by (unsurprisingly!) "stacking" them horizontally or vertically. The new functions are currently only available for some users in the Beta channel.

I am building a spreadsheet where those functions would be incredibly useful, but it has to be used by other users in the Current channel. I have three "tables" (not Excel tables, but table=shaped grids of data), with the same columns, where each column is an array formula. I would like to consolidate them into a single table, and refer to the entire content as to a single array.

Is it possible to implement some version of HSTACK and VSTACK with other array formulas?

Notes:

  • I already have access to the other, slightly older, array formulas such as SEQUENCE, FILTER, MAP, SCAN, REDUCE, as well as LAMBDA.

  • I assume that any replacement formula would be very inefficient compared to a native implementation, but this is not an issue in my case.

  • In my case, I already know that the arrays will have compatible sizes (e.g. HSTACK a 3 rows x 2 columns and 3 rows x 4 columns arrays), but I don't know the size in advance.

  • A pure formula would be preferable to a VBA UDF, but the latter could be a good solution too.



Solution 1:[1]

Here is a formula that does the vertical stacking, the ranges can be replaced with arrays, but it only does two and is not as robust as the new formula will be:

=LET(
 rngone,A1:D6,
 rngtwo,E1:I6,
rwone,ROWS(rngone),
mxseq,SEQUENCE(,MAX(COLUMNS(rngone),COLUMNS(rngtwo))),
seq,SEQUENCE(rwone+ROWS(rngtwo)),
IFERROR(CHOOSE((seq>rwone)+1,INDEX(rngone,seq,mxseq),INDEX(rngtwo,seq-rwone,mxseq)),""))

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Scott Craner