HSTACK & VSTACK: Combine Ranges Horizontally & Vertically

HSTACK VSTACK Function IN EXCEL Tutorial Page Feature Image
Learn how to use HSTACK and VSTACK in Excel to combine ranges side by side or stacked vertically. Covers SORT and UNIQUE pipelines, cross-sheet consolidation, and #N/A handling.

Merging data from separate ranges has always required copying, pasting, and then re-sorting. Every time the source data changes, you repeat the process. The VSTACK function eliminates this entirely — it stacks multiple ranges vertically into a single dynamic output that updates automatically. Similarly, the HSTACK function places ranges side by side in a single horizontal array. Both outputs spill automatically and respond instantly to changes in the source data.

Together, VSTACK and HSTACK unlock a new class of formula-driven reporting — consolidating monthly tables, combining filtered results, and assembling dynamic dashboards without any manual copy-paste steps. Furthermore, they combine naturally with SORT, UNIQUE, and FILTER to create powerful data pipelines in a single formula.

Availability: HSTACK and VSTACK require Microsoft 365. They are not available in Excel 2021, Excel 2019, or earlier standalone versions. Both functions also work in Excel for the web and Google Sheets.

What Is the Syntax for VSTACK and HSTACK?

Both functions take a simple list of arrays or ranges, separated by commas.

=VSTACK(array1, [array2], ...) → stacks arrays vertically (below each other) =HSTACK(array1, [array2], ...) → stacks arrays horizontally (side by side)
ArgumentRequired?What it does
array1RequiredThe first range or array to include. Can be a cell range, a named range, an array constant, or the result of any formula that returns an array.
array2…OptionalAdditional ranges to stack. Up to 254 arrays are supported. Each is appended below (VSTACK) or to the right (HSTACK) of the previous array.
Different-size arrays produce #N/A padding: When stacked arrays have different widths (VSTACK) or heights (HSTACK), the smaller array is padded with #N/A values to match the larger one. Wrap in IFERROR or IFNA to replace those errors with blanks or zeros. Example 3 covers this in detail.

How Do VSTACK and HSTACK Differ?

The choice between them is simple — it comes down to which direction the data should grow.

FeatureVSTACKHSTACK
DirectionVertical — arrays stack below each otherHorizontal — arrays sit side by side
Result widthWidest array's column countSum of all arrays' column counts
Result heightSum of all arrays' row countsTallest array's row count
#N/A padding whenArrays have different column countsArrays have different row counts
Best forConsolidating monthly tables, combining filtered listsAssembling side-by-side columns, building report headers

Example 1: Combine Two Lists Vertically with VSTACK

VSTACK appends one list below another and spills the result automatically. The output is fully live — if either source list grows, the combined result grows too. No formula editing is needed. This makes VSTACK ideal for consolidating data that arrives in separate batches.

1
Stack a January list and a February list into one combined column
A — Jan list
Apple
Banana
Cherry
+
C — Feb list
Mango
Papaya
E — VSTACK result
Apple
Banana
Cherry
Mango
Papaya
Stack Jan (A2:A4) below Feb (C2:C3) — enter in one cell, result spills automatically: =VSTACK(A2:A4, C2:C3) Add a third list (March in E2:E6) — just add another argument: =VSTACK(A2:A4, C2:C3, E2:E6) Use Excel Table references — the stack grows automatically as rows are added: Table[January_Data] expands when new rows appear in the source table. =VSTACK(tblJan[Item], tblFeb[Item], tblMar[Item]) Combine VSTACK with SORT to get a sorted combined list: =SORT(=VSTACK(A2:A4, C2:C3))
Enter the VSTACK formula in just one cell. Excel spills the combined output automatically into as many rows as needed. The source ranges can be anywhere in the workbook — they do not have to be adjacent or on the same sheet.

Example 2: Place Ranges Side by Side with HSTACK

HSTACK appends columns to the right of the previous array. This is useful for assembling separate columns of data that belong in the same report — for instance, joining a list of names from one table with corresponding scores from another, or building a dynamic header row from separate arrays.

2
Join a names column and a scores column from separate ranges into one table
A — Names
C — Scores
+
E — Name (HSTACK)
F — Score
Sarah
87
Sarah
87
James
94
James
94
Priya
78
Priya
78
Join column A (names) and column C (scores) side by side: Enter in one cell — the result spills across two columns automatically. =HSTACK(A2:A10, C2:C10) Add a header row using an array constant as the first argument: =HSTACK({"Name","Score"}, A2:A10, C2:C10) Wait — the header goes on a separate row. Instead, use VSTACK to add the header: =VSTACK({"Name","Score"}, =HSTACK(A2:A10, C2:C10)) Insert a blank separator column between two groups: Two empty quotes ("") create an empty column in the middle. =HSTACK(A2:B10, {""}, D2:E10)
Combine VSTACK with HSTACK for complete table assembly: VSTACK adds a header row above the data. HSTACK joins the columns horizontally. Nesting them creates a full labelled table from separate source ranges — entirely formula-driven and automatically updated.

Example 3: Handle Different-Size Arrays and #N/A Errors

When stacked arrays have different dimensions, the smaller one is padded with #N/A errors to fill the gap. VSTACK pads missing columns. HSTACK pads missing rows. Both situations are easy to handle — wrap the entire VSTACK or HSTACK formula in IFERROR or IFNA to replace the errors with a blank or a default value.

3
Stack two arrays with different column counts — handle #N/A padding cleanly
Array 1 (3 columns)
A B C
1 2 3
+
Array 2 (2 columns)
D E
4 5
VSTACK result (without fix)
A B C
1 2 3
D E ...
#N/A fills col 3
Problem: Array 2 has only 2 columns. VSTACK pads the 3rd column with #N/A. Fix with IFNA — replace #N/A with a blank string: =IFNA(=VSTACK(A1:C2, A5:B6), "") Alternative — use IFERROR for any error type (not just #N/A): IFERROR(=VSTACK(A1:C2, A5:B6), "") Replace #N/A with 0 instead of blank — useful for numeric arrays: This keeps all cells numeric, which is important for SUM formulas downstream. =IFNA(=VSTACK(A1:C2, A5:B6), 0) HSTACK with different row counts — same fix applies: Array 1 has 5 rows, Array 2 has 3 rows. HSTACK pads rows 4 and 5 with #N/A. =IFNA(=HSTACK(A1:A5, C1:C3), "")

Example 4: VSTACK + SORT + UNIQUE — The Data Pipeline

VSTACK is most powerful when combined with other dynamic array functions. A common pattern is to stack multiple lists, remove duplicates with UNIQUE, and sort the result — all in a single formula. Additionally, pairing VSTACK with FILTER lets you consolidate only the rows that meet a condition across multiple source ranges.

4
Combine three lists, remove duplicates, and sort alphabetically — one formula
Step 1 — stack three lists vertically: =VSTACK(A2:A20, C2:C15, E2:E30) Step 2 — wrap with UNIQUE to remove duplicates from the combined list: =UNIQUE(=VSTACK(A2:A20, C2:C15, E2:E30)) Step 3 — wrap with SORT for an alphabetically sorted unique combined list: =SORT(=UNIQUE(=VSTACK(A2:A20, C2:C15, E2:E30))) Conditional stack — FILTER each list before stacking. Only rows where column B = "Active" are included from each source. =VSTACK( FILTER(A2:A20, B2:B20="Active"), FILTER(C2:C15, D2:D15="Active") ) Count unique items across all three stacked lists: COUNTA(UNIQUE(VSTACK(...))) gives the combined unique count. =COUNTA(=UNIQUE(=VSTACK(A2:A20, C2:C15, E2:E30)))
This SORT(UNIQUE(VSTACK(...))) pipeline is one of the most useful formula patterns in Excel 365. It consolidates multiple ranges, deduplicates the combined result, and sorts — entirely automatically. Any change in any source list updates the final output immediately.

Example 5: Build a Dynamic Report Table with HSTACK

HSTACK lets you assemble report tables from separate formula results. Instead of placing calculated columns across a sheet manually, you can chain them horizontally and produce a self-contained, sorted, filterable report in one formula block. Moreover, inserting a blank-column separator keeps the layout visually clean.

5
Assemble a ranked leaderboard table — name, score, and rank in one formula
Source data: names in column A, scores in column B. Goal: output a sorted leaderboard table with a header row. Step 1 — sort by score descending (SORT returns name+score together): =SORT(=HSTACK(A2:A100, B2:B100), 2, -1) Step 2 — add a Rank column by inserting SEQUENCE as the first HSTACK argument: SEQUENCE generates 1, 2, 3, ..., n — one number per row of the dataset. =HSTACK( SEQUENCE(COUNTA(A2:A100)), =SORT(=HSTACK(A2:A100, B2:B100), 2, -1) ) Step 3 — add a header row with VSTACK: The final output has a header row, rank column, name column, and score column. =VSTACK( {"Rank","Name","Score"}, =HSTACK( SEQUENCE(COUNTA(A2:A100)), =SORT(=HSTACK(A2:A100, B2:B100), 2, -1) ) )
SEQUENCE inside HSTACK adds auto-numbered rows: =SEQUENCE(COUNTA(A2:A100)) generates exactly as many row numbers as there are entries — so the rank column always has the right length. No hardcoding needed. Adding new data automatically extends the numbering.

Example 6: Consolidate Data from Multiple Sheets

Before VSTACK existed, pulling data from multiple sheets into one required Power Query or complex INDIRECT formulas. VSTACK handles this directly — you can reference ranges on different sheets as separate arguments. As a result, a single formula consolidates all sheet data into one live output.

Using VSTACK Across Sheets

Each argument can reference a different sheet using the standard SheetName!Range syntax. Consequently, new data added to any source sheet appears automatically in the combined output. Furthermore, combining this with UNIQUE removes any rows that appear on more than one sheet.

6
Combine data from three monthly sheets into one consolidated view
Each source sheet has the same column structure (Name, Sales, Region). Combine January, February, and March sheets into one output. =VSTACK( January!A2:C100, February!A2:C100, March!A2:C100 ) Add a source month label as a fourth column using HSTACK. SEQUENCE + REPT approach: stack each sheet's data next to a month label. =VSTACK( =HSTACK(January!A2:C100, IF(January!A2:A100<>"", "Jan", "")), =HSTACK(February!A2:C100, IF(February!A2:A100<>"", "Feb", "")), =HSTACK(March!A2:C100, IF(March!A2:A100<>"", "Mar", "")) ) Then sort and filter the consolidated data in one further step: Sort by Region (column 3), then further FILTER as needed. =SORT(=VSTACK(January!A2:C100, February!A2:C100, March!A2:C100), 3)
Using large fixed ranges like A2:C100 ensures the formula picks up new rows automatically without editing. Empty rows within the range return blanks in the output — filter them out with FILTER if needed: =FILTER(VSTACK(...), VSTACK(...)<>"").

How to Fix Common HSTACK and VSTACK Issues

#N/A errors in the output

These appear when stacked arrays have different dimensions. VSTACK adds #N/A to missing columns. HSTACK adds #N/A to missing rows. The fix is straightforward — wrap the formula in =IFNA(VSTACK(...), "") to replace the errors with blank cells. Alternatively, use 0 if the column contains numbers that feed into calculations.

#SPILL! error

A #SPILL! error means the formula's output range is blocked by existing data. Either delete the cells in the spill range or move the formula to a location with enough clear space. Additionally, check whether another formula or a merged cell is occupying the output area.

Output includes blank rows from oversized source ranges

If you use a larger range than the data fills — for instance, A2:A100 when only 20 rows are populated — VSTACK includes the blank rows in the output. Consequently, wrap in FILTER to remove them: =FILTER(VSTACK(A2:A100, C2:C100), VSTACK(A2:A100, C2:C100)<>""). Alternatively, use Excel Tables as the source — Table references automatically exclude empty rows.

HSTACK and VSTACK require Microsoft 365: These functions produce a #NAME? error in Excel 2021, Excel 2019, and earlier standalone versions. For compatibility, use INDIRECT-based approaches or Power Query to consolidate data across ranges. If the file may be opened in older Excel, consider documenting the requirement at the top of the sheet.

Frequently Asked Questions

  • What is the difference between VSTACK and HSTACK?+
    VSTACK stacks arrays vertically — each additional array appears below the previous one. HSTACK, by contrast, stacks arrays horizontally — each additional array sits to the right of the previous one. Use VSTACK when you want to combine rows from different sources into one tall list. Use HSTACK when you want to combine columns from different sources into one wide table. Both functions spill automatically and update when the source data changes.
  • Why am I getting #N/A errors in my VSTACK result?+
    The #N/A errors appear because the stacked arrays have different numbers of columns. VSTACK pads the narrower arrays with #N/A to match the widest array. To fix this, wrap the formula in IFNA: =IFNA(VSTACK(array1, array2), ""). This replaces every #N/A with a blank. Use 0 instead of "" if the column should remain numeric for downstream calculations.
  • How do I combine VSTACK with SORT and UNIQUE?+
    Nest the functions in order — VSTACK produces the combined array, UNIQUE removes duplicates, and SORT orders the result: =SORT(UNIQUE(VSTACK(A2:A20, C2:C15, E2:E30))). Because Excel evaluates from the inside out, VSTACK runs first, then UNIQUE, then SORT. The entire output spills automatically from the cell where you enter the formula.

More Questions About HSTACK and VSTACK

  • Can VSTACK combine ranges from different sheets?+
    Yes. Each argument can reference a different worksheet using the standard SheetName!Range syntax: =VSTACK(January!A2:C100, February!A2:C100, March!A2:C100). The formula combines all three sheets into one output automatically. New rows added to any source sheet appear in the combined output without any formula changes. Pair with FILTER to exclude blank rows from oversized ranges.
  • How do I add a header row to a VSTACK or HSTACK result?+
    Include an array constant as the first argument of VSTACK: =VSTACK({"Name","Score"}, HSTACK(A2:A100, B2:B100)). The curly-brace array creates the header row. VSTACK then appends the data below it. Each value in the array constant becomes a column header matching the corresponding column in the stacked result. This produces a complete, labelled table from a single formula.
  • Which Excel versions support HSTACK and VSTACK?+
    Both functions are available only in Microsoft 365 (the subscription version). They work in Excel for the web and Google Sheets as well. Notably, they are not available in Excel 2021, Excel 2019, Excel 2016, or any earlier standalone versions — those display a #NAME? error. For cross-version files, use Power Query or INDIRECT-based approaches to consolidate data across ranges.