VSTACK and HSTACK: joining lists in Excel
=VSTACK(A2:B4,D2:E4) puts the second list underneath the first, as one list, and =HSTACK(A2:A4,C2:C4) puts lists side by side. Both are in Excel for Microsoft 365 (Windows and Mac), Excel 2024 and Excel for the web, and Google Sheets has them too; Excel 2021 and older don't. You type the formula in one cell and the answer spills into the cells below and across, and it updates when either list changes.
The formulas at a glance
| You want | Formula | What you get |
|---|---|---|
| One list under another | =VSTACK(A2:B4,D2:E4) | Both teams in one list |
| Lists side by side | =HSTACK(A2:A5,C2:C5) | Two columns that weren't next to each other |
| Lists from other sheets | =VSTACK(North!A2:B3,South!A2:B3) | One list from two tabs |
| A heading and a Total row | =VSTACK(A1:B4,D2:E4,HSTACK("Total",SUM(B2:B4,E2:E4))) | A finished table in one formula |
| Stacked and sorted | =SORT(VSTACK(A2:B4,D2:E4),2,-1) | Everyone, most hours first |
| Lists of different widths | =IFERROR(VSTACK(A2:B4,D2:D3),"") | Blanks where #N/A would be |
Each one is worked through below.
VSTACK: one list under another
Two teams keep their hours in separate tables. You want one list of everyone.
The North team has 3 rows (Amira, Ben, Cara) and the South team has 3 rows (Dev, Ewa, Finn). Stacked, that's 3 + 3 = 6 rows: the North names first, then the South names.
=VSTACK(A2:B4,D2:E4)
| A | B | C | D | E | F | G | H | |
|---|---|---|---|---|---|---|---|---|
| 1 | North | Hours | South | Hours | Everyone | Hours | ||
| 2 | Amira | 30 | Dev | 25 | Amira | 30 | ||
| 3 | Ben | 12 | Ewa | 40 | Ben | 12 | ||
| 4 | Cara | 45 | Finn | 18 | Cara | 45 | ||
| 5 | Dev | 25 | ||||||
| 6 | Ewa | 40 | ||||||
| 7 | Finn | 18 |
Start both ranges at row 2, so the headings aren't stacked in the middle. When someone changes an hour in either table, the stacked list changes too. That's the big difference from copying and pasting.
VSTACK takes as many lists as you like, one after another: =VSTACK(A2:B4,D2:E4,G2:H9).
HSTACK: lists side by side
HSTACK puts its lists next to each other, going across. It's handy for a small report from columns that aren't next to each other. Here the names are in A and the hours are in C, with the team in between:
=HSTACK(A2:A5,C2:C5)
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Name | Team | Hours | Name | Hours | |
| 2 | Amira | North | 30 | Amira | 30 | |
| 3 | Ben | North | 12 | Ben | 12 | |
| 4 | Dev | South | 25 | Dev | 25 | |
| 5 | Ewa | South | 40 | Ewa | 40 |
A list can be worked out as it goes in. =HSTACK(A2:A5,C2:C5*2) gives each name next to double their hours: Amira 60, Ben 24. To pick columns by number instead, use CHOOSECOLS (see DROP, TAKE and CHOOSEROWS).
Lists from other sheets
Each team has its own tab. VSTACK can reach across to both, so a summary sheet always has the full list. Put the sheet name and an exclamation mark before each range:
=VSTACK(North!A2:B3,South!A2:B3)
| A | B | |
|---|---|---|
| 1 | Name | Hours |
| 2 | Amira | 30 |
| 3 | Ben | 12 |
| 4 | Dev | 25 |
| 5 | Ewa | 40 |
If a tab's name has a space in it, put it in single quotes: 'North team'!A2:B3. The easiest way to get this right is to type =VSTACK(, then click the other tab and select the cells.
Lists grow, so give each range room for more rows, such as A2:B100. The empty rows come through as 0s; wrap the stack in FILTER to drop them: =FILTER(VSTACK(North!A2:B100,South!A2:B100),VSTACK(North!A2:A100,South!A2:A100)<>""). There's more on FILTER in UNIQUE and FILTER.
A heading and a Total row
VSTACK can build a whole table. Start the first range at row 1 to bring its heading along, then add a Total row made with HSTACK: the word Total next to the sum. The six people's hours add up to 30 + 12 + 45 + 25 + 40 + 18 = 170.
=VSTACK(A1:B4,D2:E4,HSTACK("Total",SUM(B2:B4,E2:E4)))
| A | B | C | D | E | F | G | H | |
|---|---|---|---|---|---|---|---|---|
| 1 | North | Hours | South | Hours | ||||
| 2 | Amira | 30 | Dev | 25 | North | Hours | ||
| 3 | Ben | 12 | Ewa | 40 | Amira | 30 | ||
| 4 | Cara | 45 | Finn | 18 | Ben | 12 | ||
| 5 | Cara | 45 | ||||||
| 6 | Dev | 25 | ||||||
| 7 | Ewa | 40 | ||||||
| 8 | Finn | 18 | ||||||
| 9 | Total | 170 |
To leave a Total row off a list instead, see DROP in DROP, TAKE and CHOOSEROWS.
Stacked and sorted
A stacked list can go straight into another function. To sort everyone by hours, biggest first, put the VSTACK inside SORT (see SORT and SORTBY):
=SORT(VSTACK(A2:B4,D2:E4),2,-1)
| A | B | C | D | E | F | G | H | |
|---|---|---|---|---|---|---|---|---|
| 1 | North | Hours | South | Hours | Most hours first | |||
| 2 | Amira | 30 | Dev | 25 | Cara | 45 | ||
| 3 | Ben | 12 | Ewa | 40 | Ewa | 40 | ||
| 4 | Cara | 45 | Finn | 18 | Amira | 30 | ||
| 5 | Dev | 25 | ||||||
| 6 | Finn | 18 | ||||||
| 7 | Ben | 12 |
Cara (45) comes first, then Ewa (40), then Amira (30). To count the people, =ROWS(VSTACK(A2:B4,D2:E4)) gives 6. To list each name once from two lists that overlap, use =UNIQUE(VSTACK(A2:A4,D2:D4)). To turn the stacked list on its side, put it inside TRANSPOSE (see TRANSPOSE and TOCOL). To add up each team's hours from a stacked list, GROUPBY can take the VSTACK as its data.
If you'd rather keep the working tidy, name the stack once with LET: =LET(all,VSTACK(A2:B4,D2:E4),SORT(all,2,-1)).
Lists of different widths
The North list has names and hours, but the South list only has names. VSTACK makes the answer as wide as the widest list and fills the gaps with #N/A. Wrap it in IFERROR to show blanks instead:
=IFERROR(VSTACK(A2:B4,D2:D3),"")
| A | B | C | D | E | F | G | H | |
|---|---|---|---|---|---|---|---|---|
| 1 | North | Hours | South | |||||
| 2 | Amira | 30 | Dev | Amira | 30 | |||
| 3 | Ben | 12 | Ewa | Ben | 12 | |||
| 4 | Cara | 45 | Cara | 45 | ||||
| 5 | Dev | |||||||
| 6 | Ewa |
IFNA works the same way here. Both also hide a real error in the data, so check the lists first.
Common mistakes
#SPILL! instead of a list
Something is in the way of the cells the answer needs. Clear the cells below and to the right of the formula. See the #SPILL! error.
Headings in the middle of the list
The second range started at row 1, so its heading was stacked too. Start it at row 2.
Lists in the wrong order
VSTACK keeps the order you give it. =VSTACK(D2:E4,A2:B4) puts the South team first. Swap the ranges, or sort the result.
#NAME? in older Excel
VSTACK and HSTACK aren't in Excel 2021 or older. Copy and paste one list under the other there. The copy won't update, so paste again when the lists change.
Try it now
In F2, make one list of all staff: the day shift, then the night shift underneath, using VSTACK. Leave out the headings.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Day shift | Night shift | All staff | |||
| 2 | Amira Khan | Dev Patel | ||||
| 3 | Ben Lewis | Ewa Nowak | ||||
| 4 | Cara Jones | Finn Walsh | ||||
| 5 | Dan Hughes | Gita Rao | ||||
| 6 | Hana Ito | |||||
| 7 | ||||||
| 8 | ||||||
| 9 | ||||||
| 10 |
Open this in Try a formula: the same sheet with the answer filled in, to change or share by link.
Part of Excel data analysis practice: every lesson on the topic, with a project in Excel.
Where it works
VSTACK and HSTACK are in Excel for Microsoft 365 on Windows and Mac, Excel 2024, Excel for the web and Google Sheets. Excel 2021 and older show #NAME?.
Questions
How do I combine data from multiple sheets with VSTACK?
Put each sheet's range in VSTACK, with the sheet name and an exclamation mark in front: =VSTACK(North!A2:B50,South!A2:B50). Type =VSTACK(, click the first tab and select the cells, type a comma, then do the same on the next tab. The list updates when any tab changes. Sheet names with spaces go in single quotes, such as 'North team'!A2:B50.
How do I stop VSTACK showing zeros for blank rows?
VSTACK copies empty cells as 0. If you've given it extra rows so the lists can grow, wrap it in FILTER to keep only the rows with a name: =FILTER(VSTACK(A2:B100,D2:E100),VSTACK(A2:A100,D2:D100)<>""). The second VSTACK stacks just the name columns, and the test keeps the rows where the name isn't empty.
Why does VSTACK give #N/A?
The lists are different widths. VSTACK makes the answer as wide as the widest list, and fills the missing cells with #N/A. Stack ranges with the same number of columns, or wrap the formula in IFERROR to show blanks: =IFERROR(VSTACK(A2:B4,D2:D3),""). HSTACK does the same with lists of different heights, filling the short one with #N/A at the bottom.
What is the difference between VSTACK and HSTACK?
VSTACK stacks vertically: the second list goes underneath the first, so the answer gets longer. HSTACK stacks horizontally: the second list goes to the right of the first, so the answer gets wider. Use VSTACK to join two lists of the same kind, such as two teams. Use HSTACK to put columns together, such as names next to their hours.