Going Stellar

Home/Google Sheets reference

Google Sheets function · Array

HSTACK in Google Sheets: syntax and examples

HSTACK appends ranges horizontally, left to right, and returns one larger array. Rows are matched by position, so it is the quick way to rebuild a table from columns that are not next to each other.

Syntax

HSTACK(range1; [range2, …])

Arguments

ArgumentTypeRequiredWhat it does
range1rangeyesThe first range or array.
range2, ...rangenoMore ranges or arrays, appended to the right in order.

Examples

The examples use this table, starting in A1:

NameCityQtyPrice
AnaCluj310
DanIasi58
MiaSibiu215
=HSTACK(A2:A4,C2:C4)

Result:

Ana3
Dan5
Mia2

Puts two separate columns side by side, skipping the City column.

Run in a Google Sheet (English US locale) on .

=HSTACK(A1:A4,D1:D4)

Result:

NamePrice
Ana10
Dan8
Mia15

Headers travel with the data when the ranges include row 1.

Run in a Google Sheet (English US locale) on .

=HSTACK(A2:A4,ARRAYFORMULA(C2:C4*D2:D4))

Result:

Ana30
Dan40
Mia30

Adds a computed column next to the names: quantity times price.

Run in a Google Sheet (English US locale) on .

=HSTACK({1;2;3},{"a";"b";"c"})

Result:

1a
2b
3c

Typed arrays work too. Here two columns of three rows each.

Run in a Google Sheet (English US locale) on .

=SORT(HSTACK(A2:A4,C2:C4),2,FALSE)

Result:

Dan5
Ana3
Mia2

Stack first, then sort the result by the second column, largest first.

Run in a Google Sheet (English US locale) on .

Common errors

  • Ranges with different heights are padded with #N/A in the missing cells. Make the ranges the same height, or wrap the result in IFERROR.
  • The result is as wide as all inputs together and as tall as the tallest one: COLUMNS(HSTACK(A1:B4,C1:C4,D1:D4)) is 4.
  • Rows are joined by position, not by key. If two tables are in a different order, align them first or use a lookup.
  • Typed arrays use "," between columns in en_US. In ro_RO the same array needs "\".

Compared with Excel

Same function and arguments as Excel 365 HSTACK.

Sources

  1. HSTACK (Docs Editors Help)

Markdown version · All functions