Locked lesson.
About this lesson
Take a first look at Excel's new set of functions for manipulating arrays. (Microsoft 365, Excel 2021 only)
Exercise files
Download this lesson’s related exercise files.
05-07-New Array Manipulation Functions-Start.xlsx15 KB 05-07-New Array Manipulation Functions-Complete.xlsx
16.9 KB 5.07 new-array-manipulation-functions-microsoft-365-excel-2021-only - Exercise.docx
52.8 KB Exercise - New Array Manipulation Functions.xlsx
17.3 KB 5.07 new-array-manipulation-functions-microsoft-365-excel-2021-only - Exercise solution.docx
95.2 KB Exercise Solution - New Array Manipulation Functions.xlsx
18.9 KB
Quick reference
New Array Manipulation Functions (Microsoft 365, Excel 2021 only)
Use the new Excel functions, VSTACK and HSTACK to manipulate and shape arrays.
When to use
We use VSTACK and HSTACK whenever we want to stack data arrays horizontally or vertically.
Instructions
VSTACK and HSTACK are two new functions available to users of Excel for Microsoft 365 that help us stack data horizontally and vertically.
VSTACK
VSTACK stands for vertical stack. We can use it to stack arrays vertically.
In this example, we need to stack just the countries from each region on top of each other to create a global sales list.
We can use VSTACK to do this.
The only arguments required are the arrays we want to stack.
Remember to hold down CTRL when selecting multiple arrays.
The VSTACK formula will stack the arrays on top of each other to produce one list. VSTACK is a dynamic array formula that spills its result to other cells. It's worth noting that dynamic array formulas can only be edited in the cell where the formula was originally typed.
We can combine VSTACK with other formulas to produce a more meaningful result. For example, maybe we want to sort the list of countries in alphabetical order (A-Z).
HSTACK
HSTACK is similar to VSTACK but it stacks arrays horizontally.
This is the result.
Use VSTACK Across Worksheets
We can use the VSTACK function to stack data from different worksheets.
In this example, we have sales data for North America, Asia, and Europe stored in three separate worksheets. We need to combine and stack the data on the Global Sales worksheet.
The data is NOT consistent across all worksheets. Some worksheets have more cities listed than others.
- Go to the Global_Sales worksheet.
- Click in cell B4.
We type the VSTACK formula in the usual way and when we specify our arrays to stack, we just need to ensure we are clicked on the correct worksheet.
Notice the VSTACK formula include the worksheet name and the cell range selected.
This is the result.
This method works well if we just have a few worksheets of data to stack. However, if we have lots of worksheets it's more efficient to use 3D referencing.
3D Referencing allows us to select the worksheets first, then select the cell range once to use in the formula. The same cell range will be used across all worksheets in the formula.
As our arrays are different lengths on each worksheet, we need to select a cell range that is large enough to accommodate the longest array.
- Go to the Global_Sales worksheet.
- Click in cell B4.
- Type =VSTACK(
- Click on the first worksheet, NA_Sales.
- Hold down SHIFT and click on the last worksheet, Europe_Sales.
The formula selects both worksheets and all worksheets in between.
- Select the longest cell range, for us that is on the NA_Sales worksheet.
Notice the zeros in some of the cells. This is because we are selecting the cell range B4:C18 on every worksheet and as the lists are different lengths, some cells don't contain any values.
We can fix this by using the FILTER function to filter out the zeros.
- Edit the formula.
- Add the FILTER function to the front of the formula.
- Click on the array argument and press CTRL+C to copy the VSTACK part of the formula.
- Press CTRL+V to paste the copied formula.
- Change the last cell reference from C18 to B18.
- Add <>"" to the end of the formula.
The zeros will now be filtered out of the stacked list.
Login to downloadLesson notes are only available for subscribers.