Skip to content

HSTACK

Places ranges or arrays side by side into one array. Shorter arrays are padded with #N/A.

Syntax

=HSTACK(, [array2], …)

Dynamic arrays

Excel for Microsoft 365, Excel 2024 and later, and Excel for the web. Not available in Excel 2021 or earlier.

Try it

Edit the formula in E2 or change the inputs. The sheet recalculates as you type.

E2
A
B
C
D
E
F
G
1
Product
Units
Price
2
Desk lamp
12
39.00
Desk lamp
468
3
Monitor arm
8
89.00
Monitor arm
712
4
Webcam
14
59.00
Webcam
826
5
6

E2 =HSTACK(A2:A4,B2:B4*C2:C4) returns Desk lamp, 468; Monitor arm, 712; Webcam, 826

How HSTACK works

HSTACK joins arrays side by side. It builds one array out of several columns, ranges or calculated results, so you can put a lookup result, a calculation and a label next to each other with a single formula.

The arguments

Each array can be a range, an array constant, or the output of a formula. =HSTACK(A2:A4,C2:C4) returns the product names and prices from columns that aren't next to each other. The array on the left of the formula is the leftmost in the result.

Adding a calculated column

HSTACK is how you return a table and a column that you calculate in the same formula, without a helper column in the data:

=HSTACK(A2:A4,B2:B4*C2:C4)

The second argument multiplies Units by Price for every row at once and returns the revenue column. The first returns the names. Together they form a two-column array that spills from one cell.

Numbering a list

Pair a list with SEQUENCE to number it: =HSTACK(SEQUENCE(ROWS(A2:A4)),A2:A4). The numbers adjust whenever the list gets longer or shorter.

When the heights differ

The result is as tall as the tallest array. A shorter array is padded with #N/A at the bottom. =HSTACK(A2:A4,E2:E3) has three rows because column A has three, and the second column gets #N/A in its third row. Use IFNA to replace the padding: =IFNA(HSTACK(A2:A4,E2:E3),"").

HSTACK, CHOOSECOLS and VSTACK

CHOOSECOLS picks columns out of one array. HSTACK builds one array from separate pieces, so the two often appear together: HSTACK to bring the pieces together, CHOOSECOLS to trim the combined result. VSTACK does the same job vertically. The pair lets you build any table shape: stack the rows, then join the columns.

Notes

Use it to reorder columns of a table you can't move: =HSTACK(C2:C4,A2:A4) puts column C first. Blank cells come back as 0. The result spills to the right and down, so the cells it needs must be empty or you get #SPILL!. See FILTER for spill ranges and the # operator.

HSTACK needs Microsoft 365, Excel 2024 or later, or Excel for the web. In older versions the formula returns #NAME?.

Arguments

array1
The first range or array. It forms the leftmost columns of the result.
array2, …optional
More ranges or arrays, each placed to the right of the one before. They can be ranges from anywhere in the workbook, array constants, or the results of other formulas.

Examples

Each example is a live sheet. Change the inputs or the formula and watch the result.

Example 1

Add a calculated column next to a list

E2 =HSTACK(A2:A4,B2:B4*C2:C4)

Result: Desk lamp, 468; Monitor arm, 712; Webcam, 826

The second argument multiplies each Units value by the Price in the same row. Revenue is calculated inside the formula, with no helper column.

E2
A
B
C
D
E
F
G
1
Product
Units
Price
2
Desk lamp
12
39.00
Desk lamp
468
3
Monitor arm
8
89.00
Monitor arm
712
4
Webcam
14
59.00
Webcam
826
5
6

E2 =HSTACK(A2:A4,B2:B4*C2:C4) returns Desk lamp, 468; Monitor arm, 712; Webcam, 826

Example 2

Join two columns that are not next to each other

E2 =HSTACK(A2:A4,C2:C4)

Result: Desk lamp, 39; Monitor arm, 89; Webcam, 59

The Units column in between is skipped. Each range is placed against the previous one.

E2
A
B
C
D
E
F
G
1
Product
Units
Price
2
Desk lamp
12
39
Desk lamp
39
3
Monitor arm
8
89
Monitor arm
89
4
Webcam
14
59
Webcam
59
5
6

E2 =HSTACK(A2:A4,C2:C4) returns Desk lamp, 39; Monitor arm, 89; Webcam, 59

Example 3

Number a list with SEQUENCE

E2 =HSTACK(SEQUENCE(ROWS(A2:A4)),A2:A4)

Result: 1, Desk lamp; 2, Monitor arm; 3, Webcam

ROWS counts the items, so SEQUENCE produces exactly as many numbers as the list has.

E2
A
B
C
D
E
F
G
1
Product
Units
Price
2
Desk lamp
12
39
1
Desk lamp
3
Monitor arm
8
89
2
Monitor arm
4
Webcam
14
59
3
Webcam
5
6

E2 =HSTACK(SEQUENCE(ROWS(A2:A4)),A2:A4) returns 1, Desk lamp; 2, Monitor arm; 3, Webcam

Example 4

A shorter array is padded with #N/A

G2 =HSTACK(A2:A4,E2:E3)

Result: Desk lamp, 2; Monitor arm, 1; Webcam, #N/A

The Returns range has only two rows, so the third row of the second column is #N/A. IFNA(...,0) would turn it into a zero.

G2
A
B
C
D
E
F
G
1
Product
Units
Price
Returns
2
Desk lamp
12
39
2
Desk lamp
3
Monitor arm
8
89
1
Monitor arm
4
Webcam
14
59
Webcam
5
6

G2 =HSTACK(A2:A4,E2:E3) returns Desk lamp, 2; Monitor arm, 1; Webcam, #N/A

Your turn.

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 2

In E2, return each product name with its revenue (units times price) next to it. Do it in one formula, with no helper column.

Answer in E2.

E2
A
B
C
D
E
F
G
H
I
1
Product
Units
Price
2
Gloves
40
3
3
Tape
25
2
4
Wrap
10
8
5
Labels
60
1
6
Bags
35
4
7
8

Common mistakes

  • Arrays of different heights do not raise an error. The shorter one is padded with #N/A. Wrap the formula in IFNA(HSTACK(...),"") or make sure each range covers the same rows.
  • HSTACK joins by position, not by key. It does not look anything up: row 3 of one array is placed beside row 3 of the next. If the two lists are in a different order, use XLOOKUP to line them up first.
  • Headers are only included if the ranges include them. To add one, stack an array constant on top with VSTACK, as in =VSTACK({"Product","Revenue"},HSTACK(...)).
  • Blank cells inside a source range come back as 0.
  • #SPILL! means something is in the cells the result needs to fill, to the right of or below the formula.

Questions people ask

How do I combine columns side by side with a formula?

Use `=HSTACK(A2:A10,C2:C10,E2:E10)`. Each range becomes the next column of the result. They do not need to be adjacent in the sheet.

How do I add a calculated column to a spilled result?

Include the calculation as an argument: `=HSTACK(A2:A4,B2:B4*C2:C4)`. Excel works it out for every row and returns it beside the other columns.

Why does HSTACK return #N/A?

The arrays have different heights, and HSTACK pads the shorter one with `#N/A`. Use `IFNA(...,"")` around it, or correct the ranges so they have the same number of rows.

How do I reorder columns without moving them?

Use HSTACK to list the ranges in the order you want, or CHOOSECOLS to pick them by position. `=HSTACK(C2:C4,A2:A4)` puts column C first.

Does HSTACK work in Excel 2021?

No. It is available in Microsoft 365, Excel 2024 and later, and Excel for the web. In earlier versions the formula returns `#NAME?`.

Learn HSTACK in a real sheet.

HSTACK is taught in Data analysis with formulas, lesson 21: A summary table from one formula. Each lesson is a short, graded exercise like the one above.