The HSTACK function in Excel is a powerful tool designed to combine several arrays or ranges horizontally. This function takes multiple inputs and appends them next to each other, creating a wider array. It is especially useful when users need to consolidate data from different sources or formats into a single, streamlined view.
Syntax
HSTACK(array1, [array2], …)
- array1: The first array or range to be combined.
- array2: (Optional) Additional arrays or ranges to be combined, separated by commas.
Example #1
=HSTACK(A1:B2, D1:D3)
This function joins the range A1:B2 with the range D1:D3, combining two data sets side-by-side. For instance, if A1:B2 contains:
| 1 | 2 |
|—|—|
| 3 | 4 |
And D1:D3 contains:
| 5 |
|—|
| 6 |
| 7 |
The result would be:
| 1 | 2 | 5 |
|—|—|—|
| 3 | 4 | 6 |
| | | 7 |
Example #2
=HSTACK(A1:A3, B1:B3, C1:C3)
This example combines three vertical ranges, A1:A3, B1:B3, and C1:C3, side by side. If these ranges hold:
| A | B | C |
|—|—|—|
| 1 | 2 | 3 |
| 4 | 5 | 6 |
| 7 | 8 | 9 |
The output will be:
| A | B | C |
|—|—|—|
| 1 | 2 | 3 |
| 4 | 5 | 6 |
| 7 | 8 | 9 |
Example #3
=HSTACK(A1:A2, B1)
In this scenario, HSTACK tries to combine a two-row array (A1:A2) with a single cell (B1). If A1:A2 contains:
| 1 |
|—|
| 2 |
And B1 contains 3, the outcome will be:
| 1 | 3 |
|—|—|
| 2 | |
Error handling
- VALUE!: This error occurs if the input arrays are of different sizes in terms of rows, and it cannot fill the combined array properly.
- REF!: This indicates that a reference is invalid or deleted. Ensure that all specified ranges exist and are correctly referenced.
- N/A: This error shows up when one of the arrays is empty or not valid, causing the function to fail in concatenation.