How to Use the HSTACK Function in Google Sheets to Combine Data Ranges Horizontally

Consolidating data scattered across multiple worksheets, disparate columns, or dynamic formula outputs is one of the most frequent spreadsheet tasks in business reporting and financial analysis. Historically, merging separate columns side-by-side in Google Sheets required manual copy-pasting, rigid array literals enclosed in curly brackets ({range1, range2}), or complicated multi-step lookup formulas. The native HSTACK (Horizontal Stack) function solves this challenge cleanly. It appends multiple cell ranges, arrays, and formula outputs horizontally into a single, cohesive, dynamic array.

What Is the HSTACK Function and How Does It Work?

The HSTACK function takes two or more array arguments and places them side-by-side along the horizontal axis (adding new columns from left to right):

  • Dynamic Spilling: As source ranges expand or update, the output array automatically recalculates and spills across your sheet.
  • Handling Uneven Row Heights: If the source ranges contain different numbers of rows, HSTACK automatically pads the shorter ranges with #N/A errors to maintain rectangular alignment (which can be cleanly wrapped using IFNA).
  • Integration with Filtering and Querying: HSTACK seamlessly combines the outputs of functions such as FILTER, UNIQUE, SORT, and QUERY into customised side-by-side tables.

Syntax and Arguments for HSTACK

The syntax for the HSTACK function in Google Sheets is straightforward:

=HSTACK(range1, [range2, ...])
  • range1: The initial cell range or array to place on the left.
  • range2, ...: (Optional) One or more additional cell ranges, arrays, or formula outputs to append consecutively to the right.

Step-by-Step Examples of Using HSTACK in Google Sheets

Example 1: Combining Two Adjacent or Distant Column Ranges

Suppose you have customer names in cells A2:A20 on Sheet1 and their corresponding order transaction IDs in cells D2:D20 on Sheet2. To merge them side-by-side into a consolidated summary table:

=HSTACK(Sheet1!A2:A20, Sheet2!D2:D20)

Google Sheets generates a clean two-column table beginning at the cell where you input the formula.

Example 2: Combining Three Arrays with Static Column Headers

You can combine static text headers and dynamic data arrays simultaneously using HSTACK and VSTACK together:

=VSTACK(
    HSTACK("Employee ID", "Full Name", "Department"),
    HSTACK(A2:A10, B2:B10, C2:C10)
)

This creates a completely self-contained reporting table with properly labelled headers spanning columns across the page.

Example 3: Handling Ranges of Unequal Row Lengths with IFNA

When stacking ranges that possess different numbers of rows, HSTACK naturally displays #N/A where rows do not align. For instance, stacking A2:A10 (9 rows) with B2:B5 (4 rows) results in cells 5 through 9 of the second column displaying #N/A.

To replace those unsightly error markers with empty blank cells, wrap the entire expression inside an IFNA wrapper:

=IFNA(HSTACK(A2:A10, B2:B5), "")

Now, any missing row slots display cleanly as blank cells rather than error codes.

Example 4: Combining Filtered Datasets Horizontally

You can use HSTACK to juxtapose two completely different filtered datasets for side-by-side comparison:

=HSTACK(
    FILTER(A2:B20, C2:C20 = "North"),
    FILTER(D2:E20, F2:F20 = "South")
)

This displays North region results in columns 1 and 2 alongside South region metrics in columns 3 and 4 without requiring separate helper worksheets.

HSTACK vs Array Literals {A, B}

While curly bracket array literals (={A2:A10, B2:B10}) can achieve horizontal combination, HSTACK provides substantial advantages:

  • Locale Independence: Array literal syntax varies across international regions (some countries use commas, others use backslashes or semicolons to separate columns). HSTACK uses standard universal comma-separated arguments worldwide.
  • Graceful Uneven Handling: Array literals throw a fatal #VALUE! error if row counts do not match exactly. HSTACK succeeds and pads missing cells gracefully.
  • Readability: Complex nested formulas are considerably easier to audit and troubleshoot when named functions like HSTACK and VSTACK are used instead of nested punctuation marks.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.