How to Use the VSTACK and HSTACK Functions in Microsoft Excel to Combine Data Tables

Consolidating data from multiple worksheets, monthly accounting exports, or regional departmental reports into a single unified master table is an everyday requirement in Microsoft Excel. For years, combining tables meant either copying and pasting ranges manually—a brittle approach that breaks whenever underlying numbers update—or building complex Power Query mashups and VBA macros. Microsoft modernised spreadsheet consolidation with two powerful dynamic array functions: VSTACK (Vertical Stacking) and HSTACK (Horizontal Stacking). These functions allow you to stitch multiple ranges or arrays together into a single dynamic spilled table that updates instantly when source numbers change.

Understanding VSTACK and HSTACK Mechanics

Both functions take two or more arrays and append them along distinct axes:

  • VSTACK: Appends arrays vertically (stacking tables top-to-bottom). This is ideal for merging monthly sales sheets, consolidating regional staff rosters, or appending quarterly transaction logs.
  • HSTACK: Appends arrays horizontally (stitching tables side-by-side). This is perfect for combining separate metric columns—such as joining customer ID columns with address tables or quarterly sales figures.

The syntax for both functions is elegant and straightforward:

=VSTACK(array1, [array2], ...)
=HSTACK(array1, [array2], ...)

Step-by-Step: Stacking Three Monthly Tables with VSTACK

Suppose you have three separate worksheets named Jan, Feb, and Mar, each containing an identical 4-column sales table from rows 2 to 50 (with row 1 containing headers).

To combine the actual data rows without duplicating headers, navigate to your master summary sheet and enter this formula into cell A2:

=VSTACK(Jan!A2:D50, Feb!A2:D50, Mar!A2:D50)

Excel instantly stitches all three ranges together in sequence, spilling the combined 147 rows downward into a single contiguous block. If a figure is updated on the February sheet, the consolidated table refreshes immediately.

Stitching Side-by-Side Tables with HSTACK

If you have client demographic data in columns A2:B20 and their corresponding billing metrics in columns F2:G20, consolidate them into a 4-column layout side-by-side using HSTACK:

=HSTACK(A2:B20, F2:G20)

The resulting array pairs the corresponding rows horizontally across four contiguous columns.

Handling Uneven Array Sizes and #N/A Padding

When stacking arrays that do not share the exact same number of columns (with VSTACK) or rows (with HSTACK), Excel handles the missing cells by populating them with #N/A error badges.

To replace these unsightly #N/A badges with clean blanks or dashes, wrap the function with IFNA:

=IFNA(VSTACK(Table1, Table2), "")

Any column or row discrepancy is cleanly padded with an empty string rather than an error marker.

Advanced Synergy: Pairing VSTACK with FILTER and SORT

In real-world business scenarios, source tables often contain blank rows at the bottom. Stacking open-ended ranges like A2:D will pull hundreds of empty rows into your master table.

To filter out blank rows dynamically before stacking, nest the FILTER function inside VSTACK:

=VSTACK(
  FILTER(Jan!A2:D100, Jan!A2:A100 <> ""),
  FILTER(Feb!A2:D100, Feb!A2:A100 <> "")
)

To sort the entire consolidated dataset alphabetically by client name (Column 1) after stacking:

=SORT(VSTACK(Jan!A2:D50, Feb!A2:D50), 1, 1)

Excel Table Stacking Functions Comparison

Function Stacking Orientation Required Dimension Match Uneven Dimension Result
VSTACK Vertical (Top to Bottom) Equal Column Count Pads missing columns with #N/A
HSTACK Horizontal (Left to Right) Equal Row Count Pads missing rows with #N/A
CHOOSEROWS Vertical Row Selection N/A (Subset extraction) Selects specific indexed rows
CHOOSECOLS Horizontal Column Selection N/A (Subset extraction) Selects specific indexed columns

Frequently Asked Questions

Which versions of Microsoft Excel support VSTACK and HSTACK?

VSTACK and HSTACK are supported in Microsoft 365 (Windows, Mac, and Web) and Excel 2024. Legacy standalone versions such as Excel 2019 and Excel 2016 do not support dynamic array stacking functions.

Can I stack official Excel Structured Tables (ListObjects)?

Yes. You can reference Excel table names directly: =VSTACK(Table_North, Table_South). If both tables share identical column schemas, VSTACK compiles their body rows seamlessly.

Can VSTACK combine data across different workbook files?

Yes, provided the secondary workbooks are open in the same Excel session. If the external workbooks are closed, referencing them may require clicking to update external links or using Power Query for background data connections.

Get the best tech tips delivered straight to your inbox.

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