Section: Excel & Google Sheets

The VSTACK function in Excel stacks ranges on top of each other, and HSTACK puts them side by side. Both return one array from several, so you can combine ranges in Excel with a single formula instead of copying and pasting each list below the last. This guide shows how to merge two lists in Excel, how to combine data from multiple sheets, what the #N/A cells mean when the ranges differ in size, and where these Excel dynamic array functions are available.
What VSTACK and HSTACK do
Microsoft describes VSTACK as appending arrays vertically and in sequence to return a larger array. HSTACK does the same horizontally. Neither one changes the source ranges. They build a new spill range somewhere else, and that range updates when the sources change.
That is the real gain over copy and paste. A monthly list you stacked by hand is out of date the moment someone edits January. A stacked formula is not.
The syntax
=VSTACK(array1, [array2], ...)=HSTACK(array1, [array2], ...)
Each argument is an array: a range, a table column, or the result of another function. You can pass as many as you need. Only the first is required.
The size of the result follows two simple rules from Microsoft's remarks. For VSTACK, the rows are the combined row count of all the arrays, and the columns are the largest column count among them. For HSTACK, it is the other way round: the columns are added up, and the rows are the largest row count.

Stack two lists with VSTACK
Say January sits in A2:B4 and February in D2:E3. January lists Pens 12, Paper 30 and Ink 45. February lists Pens 15 and Tape 8. The formula is:
=VSTACK(A2:B4,D2:E3)
It returns five rows and two columns, with January first and February underneath. The January amounts add up to 87 and the February amounts to 23, so a SUM over the stacked amounts gives 110. If that total does not match the two separate sums, the ranges were not what you thought they were.
Leave the headers out of the ranges you stack, then type one header row above the formula. Otherwise each range brings its own header row into the middle of the data.

Place ranges side by side with HSTACK
HSTACK is for columns. If product names are in A2:A4, units in C2:C4 and prices in F2:F4, then =HSTACK(A2:A4,C2:C4,F2:F4) returns a clean three-column block with the columns you want and none of the ones in between. It is a quick way to pull out and reorder columns without touching the original table.
You can nest the two. =VSTACK(HSTACK(...),HSTACK(...)) builds a block piece by piece, which helps when a report needs a label column added to the left of each stacked range.
When the ranges are different sizes
VSTACK fills the missing cells with #N/A when one array has fewer columns than the widest. If a two-column list is stacked with a three-column list, the two-column rows get #N/A in the third column. HSTACK does the same for rows when one array is shorter than the tallest.
Microsoft's fix is to wrap the formula in IFERROR and choose your own value: =IFERROR(VSTACK(A2:B4,D2:F3),"") leaves those cells blank. One caution: IFERROR hides every error in the result, not only the padding, so use it once you have checked that the sources are clean.

Combine data from multiple sheets
The most useful job for VSTACK is a roll-up. If each month has its own sheet with the same layout, =VSTACK(Jan!A2:B4,Feb!A2:B3,Mar!A2:B6) gives you one list with no manual copying. Add a new month by adding one more argument.
If your data lives in Excel tables, refer to the table data rather than a fixed address, so the stacked list grows when a table does.
Combine VSTACK with other functions
Because the result is an array, anything that accepts an array accepts a stack. Wrap it in UNIQUE to drop repeated rows after merging two lists, or in SORT and FILTER to order and narrow the combined list in one formula. This is how most people merge two lists in Excel without Power Query.
Where the functions are available
Microsoft lists VSTACK and HSTACK for Excel for Microsoft 365, Excel for Microsoft 365 for Mac, Excel for the web, Excel 2024 and Excel 2024 for Mac. Older versions do not have them. If a colleague on an older version opens your file, they see an error where the stacked range should be, so check the version before you send it.

Common problems
- #SPILL! error. Something sits in the cells the result needs. Clear the block. The spill error guide covers the other causes.
- #N/A in the extra columns. The arrays have different widths. Match the ranges or wrap in IFERROR.
- #NAME? error. Your Excel version does not have the function.
- Headers in the middle of the data. Each range included its own header row. Stack data rows only.
- Totals look too high. Two ranges overlap, so the same rows are counted twice.
- The result does not update. Calculation is set to manual. Switch it to automatic.
Questions and answers
What is the difference between VSTACK and HSTACK?
VSTACK joins arrays top to bottom and adds up the rows. HSTACK joins them left to right and adds up the columns.
Can VSTACK combine ranges from different sheets?
Yes. Put each sheet reference in its own argument.
Why do I get #N/A cells?
The arrays are different sizes, and Excel pads the shorter ones with #N/A.
Do the source ranges change?
No. The functions only read them.
Does it work in Excel 2019?
Microsoft does not list it there. It lists Microsoft 365, Excel 2024 and Excel for the web.
