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
| Argument | Type | Required | What it does |
|---|---|---|---|
range1 | range | yes | The first range or array. |
range2, ... | range | no | More ranges or arrays, appended to the right in order. |
Examples
The examples use this table, starting in A1:
| Name | City | Qty | Price |
| Ana | Cluj | 3 | 10 |
| Dan | Iasi | 5 | 8 |
| Mia | Sibiu | 2 | 15 |
=HSTACK(A2:A4,C2:C4)Result:
| Ana | 3 |
| Dan | 5 |
| Mia | 2 |
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:
| Name | Price |
| Ana | 10 |
| Dan | 8 |
| Mia | 15 |
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:
| Ana | 30 |
| Dan | 40 |
| Mia | 30 |
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:
| 1 | a |
| 2 | b |
| 3 | c |
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:
| Dan | 5 |
| Ana | 3 |
| Mia | 2 |
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.