Cellwise Start free

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.

ABC
1RepJanFeb
2Priya1840021250
3Marcus1520014900
4Lena2010022400
5Tom1680017350
  1. =HSTACK(A2:A5,C2:C5)

    Result: spills 4 rows × 2 columns

    Priya21250
    Marcus14900
    Lena22400
    Tom17350

    Puts the names next to February only, skipping the January column.

  2. =HSTACK(A2:A5,B2:B5+C2:C5)

    Result: spills 4 rows × 2 columns

    Priya39650
    Marcus30100
    Lena42500
    Tom34150

    Adds a calculated column: each rep with their two-month total.

  3. =SORT(HSTACK(A2:A5,B2:B5+C2:C5),2,-1)

    Result: spills 4 rows × 2 columns

    Lena42500
    Priya39650
    Tom34150
    Marcus30100

    Sorts that two-column result by the total, highest first: Lena leads with 42,500.

  4. =HSTACK("Total",SUM(B2:B5),SUM(C2:C5))

    Result: spills 1 row × 3 columns

    Total7050075900

    Single values work too: a totals row with a label and one sum per month.

How to use HSTACK

  1. Click the top-left cell of an empty area.
  2. Type =HSTACK( and select the first range.
  3. Add a comma and the next range or value, as many as you need.
  4. 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

Updated