How to Use HSTACK Function in Excel + Tips

Learn how to use HSTACK function in Excel step-by-step to combine ranges horizontally side-by-side with simple examples and tips.

Advertisement
Formula
=HSTACK(array1, [array2], ...)

Hello everyone! Today i will show you how to use HSTACK function in Microsoft Excel step by step.


1. What is HSTACK Function in Excel?

The HSTACK function (Horizontal Stack) is a dynamic array function introduced in Excel 365 and Excel 2024. It allows you to combine two or more cell ranges or arrays side-by-side horizontally (left-to-right) into a single combined table.

Unlike manually copying and pasting columns next to each other, HSTACK is fully dynamic: whenever your original data updates, the combined table updates automatically!


2. 🛠️ Formula Syntax & Parameters

=HSTACK(array1, [array2], ...)
  • array1: Required. The first array or range of cells to combine.
  • [array2], ...: Optional. Additional arrays or cell ranges to attach side-by-side to the right of array1.

Advertisement

3. 📋 Practical Examples

Example 1: Combine Two Non-Adjacent Columns Side-by-Side

Suppose cell range A2:A5 contains Employee Names and cell range C2:C5 contains Sales Amounts (skipping Column B):

CellColumn A (Name)Column B (Dept)Column C (Sales)
2SokIT$500
3DaraHR$700
4LinaIT$800
5SamSales$600
=HSTACK(A2:A5, C2:C5)

👉 Result: Returns a new 2-column table joining Name and Sales side-by-side, skipping Column B completely!


Example 2: Reorder Table Columns for Reports

You can use HSTACK to rearrange columns into a new order without modifying your original worksheet layout.

To display Sales (Col C) first and Name (Col A) second:

=HSTACK(C2:C5, A2:A5)

👉 Result:

Column 1 (Sales)Column 2 (Name)
$500Sok
$700Dara
$800Lina
$600Sam

Example 3: Stack Ranges with Different Heights (Handling Missing Cells)

If array1 has 4 rows (A2:A5) and array2 has only 3 rows (D2:D4), HSTACK fills the missing cell in the shorter column with a #N/A error:

=HSTACK(A2:A5, D2:D4)

Wrap with IFNA to clean up #N/A errors:

=IFNA(HSTACK(A2:A5, D2:D4), "")

👉 Result: Replaces any missing row entries with a clean blank space "" instead of showing #N/A!


💡 Quick Tips for Using HSTACK Function

  1. Clean Up Missing Values with IFNA: When stacking ranges of different heights/row counts, wrap HSTACK inside IFNA(HSTACK(...), "") to replace #N/A errors with blank cells.
  2. Easily Create Custom Lookup Tables: HSTACK is great for creating temporary 2-column arrays inside XLOOKUP or VLOOKUP when your lookup column is located to the right of your return column.
  3. Combine with CHOOSECOLS or SORT: You can nest HSTACK inside SORT to sort your combined horizontal table automatically: =SORT(HSTACK(A2:A5, C2:C5), 2, -1).
  4. Excel Version Requirement: HSTACK requires Microsoft 365, Excel 2024, or Excel for the Web.

📚 Related Resources & Tutorials

Found this tutorial helpful? Share it with colleagues:
📚

Related Tutorials

Opens in new tab ↗
Advertisement