Dynamic arrays function
Excel HSTACK function
HSTACK places ranges, arrays or single values side by side and returns them as one spilled array. Use it to build a report from columns that are not next to each other, or to add a calculated column to a table.
=HSTACK(array1, [array2], ...)Arguments
array1- The first range, array or value. It goes on the left.
array2- Optional. More pieces, each placed to the right of the one before.
HSTACK examples
Every result below was calculated from this sample sheet by the same spreadsheet engine the Cellwise app uses.
| A | B | C | |
|---|---|---|---|
| 1 | Rep | Jan | Feb |
| 2 | Priya | 18400 | 21250 |
| 3 | Marcus | 15200 | 14900 |
| 4 | Lena | 20100 | 22400 |
| 5 | Tom | 16800 | 17350 |
Result: spills 4 rows × 2 columns
Priya 21250 Marcus 14900 Lena 22400 Tom 17350 Puts the names next to February only, skipping the January column.
Result: spills 4 rows × 2 columns
Priya 39650 Marcus 30100 Lena 42500 Tom 34150 Adds a calculated column: each rep with their two-month total.
Result: spills 4 rows × 2 columns
Lena 42500 Priya 39650 Tom 34150 Marcus 30100 Sorts that two-column result by the total, highest first: Lena leads with 42,500.
Result: spills 1 row × 3 columns
Total 70500 75900 Single values work too: a totals row with a label and one sum per month.
How to use HSTACK
- Click the top-left cell of an empty area.
- Type =HSTACK( and select the first range.
- Add a comma and the next range or value, as many as you need.
- Close the bracket and press Enter.
Common HSTACK mistakes
Pieces of different heights
HSTACK fills the gaps below a shorter piece with #N/A. Make the ranges the same height, or wrap it: =IFERROR(HSTACK(...),"").
Expecting joined text
HSTACK keeps each piece in its own cell. To join text into one cell, use & or TEXTJOIN.
Using it in older Excel
HSTACK needs Microsoft 365, Excel 2024 or Excel for the web. Older versions show #NAME?.
HSTACK FAQ
How do I combine two columns side by side with a formula?
=HSTACK(A2:A5,C2:C5) returns both columns next to each other as one array, and it updates when the data changes.
Why does HSTACK show #N/A?
One piece has fewer rows than the others, and HSTACK pads the missing cells with #N/A. Wrap it in IFERROR to show blanks instead.
What is the difference between HSTACK and VSTACK?
HSTACK puts pieces side by side, left to right. VSTACK stacks them one under another, top to bottom.
Related functions
VSTACKStacks arrays one under anotherCHOOSECOLSPicks columns, spillsSORTSorts a range, spillsFILTERKeeps matching rows, spills
Updated