# How to use the VSTACK function

The VSTACK function lets you combine cell ranges or arrays, it joins data to the first blank cell at the bottom of a cell range or array.

Formula in cell E3:

The VSTACK function is available to Excel 365 users and is in the "Array manipulation" category.

#### Table of Contents

## 1. VSTACK Function Syntax

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

## 2. VSTACK Function Arguments

array1 | Required. The first cell range or array. |

[array2] | Optional. The second cell range or array to merge. |

## 3. VSTACK Function example

The image above demonstrates how the VSTACK function merges the ranges B2:D4 (blue) and F2:H4 (red). It appends the second cell range (red) to the bottom of the first cell range (blue).

Formula in cell E4:

### 3.1 Explaining formula

#### Step 1 - VSTACK function

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

#### Step 2 - Populate arguments

*array1 - B2:D4
[array2] - F2:H:4*

#### Step 3 - Evaluate function

VSTACK(B2:D4, F2:H:4)

becomes

VSTACK({89, 68, 19;27, 84, 92;26, 98, 62}, {37, 89, 99;63, 8, 1;100, 31, 70})

and returns

{89, 68, 19;

27, 84, 92;

26, 98, 62;

37, 89, 99;

63, 8, 1;

100, 31, 70}

## 4. VSTACK Function errors

The image above demonstrates what happens when you try to append two cell ranges containing a different number of columns. The first cell range (blue) has three columns and the second cell range (red) has 2 columns.

The result is an array containing #N/A errors in locations where no value exists.

Formula in cell E4:

The IFNA function lets you remove #N/A errors.

Formula in cell E4:

### 4.1 Explaining formula

#### Step 1 - Stack cell ranges vertically

VSTACK(B2:D4, F2:G:4)

becomes

VSTACK(

{89, 68, 19;

27, 84, 92;

26, 98, 62},

{37, 89;

63,8;

100, 31})

and returns

{89, 68, 19;

27, 84, 92;

26, 98, 62;

37, 89, #N/A;

63, 8, #N/A;

100, 31, #N/A}

#### Step 2 - Remove #N/A errors

IFNA(VSTACK(B2:D4, F2:G:4), "")

becomes

IFNA({89, 68, 19;

27, 84, 92;

26, 98, 62;

37, 89, #N/A;

63, 8, #N/A;

100, 31, #N/A}, "")

and returns

{89, 68, 19;

27, 84, 92;

26, 98, 62;

37, 89, "";

63, 8, "";

100, 31, ""}

## 5. VSTACK Function alternative

There is unfortunately no way to merge cell ranges in earlier Excel versions unless you are willing to manually merge the ranges or use a User Defined Function.

The image above shows how to manually merge two cell ranges, this technique works in all Excel versions as far as I know, however, you are required to enter the array as an array formula in order to show all values.

Here are the steps:

- Select cell range B8:D:13. The resulting array is three columns wide and contains six rows, make sure you select a cell range that fits your data.
- Type = (equal sign).
- Select with mouse the first cell range B2:D4.
- Type a + (plus sign).
- Select with mouse the second cell range F2:H4.
- Select F2:H4 in the formula.

- Press F9 to convert the cell range to constants.

- Repeat steps 6 and 7 using the first cell range B2:D4, the result looks like this:

- Select the last curly bracket of the first array, the plus sign and the first curly bracket of the second array:

- Press Delete to remove those characters.
- Type a semicolon ;
- Steps 12 to 14 show how to enter the array as an array formula.

Press and hold CTRL + SHIFT simultaneously. - Press Enter once.
- Release all keys.

The formula has now a leading and ending curly bracket, they appear automatically. Don't enter these characters yourself.

This article describes how to merge cell ranges using a User Defined Function: Combine cell ranges ignore blank cells (User Defined Function)

## 6. Extract unique distinct rows from multiple cell ranges

Formula in cell B9:

### Explaining formula

#### Step 1 - Join cell ranges

VSTACK(*array1*,[*array2*],...)

VSTACK(B3:D5, F3:H5)

becomes

VSTACK({89, "Charles", 19;

27, "Tina", 45;

26, "Linda", 62},

{89, "Charles", 24;

27, "Tina", 45;

26, "Laura", 62})

and returns

{89, "Charles", 19;

27, "Tina", 45;

26, "Linda", 62;

89, "Charles", 24;

27, "Tina", 45;

26, "Laura", 62}.

#### Step 2 - Extract unique distinct rows

The UNIQUE function is a new Excel 365 function that returns unique and unique distinct values/rows.

UNIQUE(*array,[by_col],[exactly_once]*)

UNIQUE(VSTACK(B3:D5, F3:H5), FALSE, FALSE)

becomes

UNIQUE({89, "Charles", 19;

**27, "Tina", 45;**

26, "Linda", 62;

89, "Charles", 24;

**27, "Tina", 45;**

26, "Laura", 62}, FALSE, FALSE)

and returns

{89, "Charles", 19;

27, "Tina", 45;

26, "Linda", 62;

89, "Charles", 24;

26, "Laura", 62}

The bolded rows are duplicates, only one instance of those rows in the result.

## 7. VSTACK Function - 3D range

The image above demonstrates how to use 3D ranges in the VSTACK function. You must have data in the same location on each worksheet for this to work.

Dynamic array formula in cell B3:

### 7.1 How to enter the 3D range

This is entered as a regular formula, however, the 3D range needs to be explained in greater detail.

To create this reference: '1:3'!A2:C10 follow these steps:

- Double press with left mouse button on cell B3, the prompt appears.
- Type: =FILTER(VSTACK(
- Go to worksheet: 1
- Select cell range A2:C10

- Press and hold SHIFT key.
- Select the remaining worksheets, they are 2 and 3 in this example.

- Type the remaining part of the formula and repeat the above steps for the second 3D range.
- Press Enter.

### 7.2 Explaining formula

#### Step 1 - Merge data from three diffrent worksheets vertically

VSTACK('1:3'!A2:C10)

becomes

VSTACK('1'!A2:C10,'2'!A2:C10,'3'!A2:C10)

becomes

VSTACK({89,"Charles",19;

27,"Tina",45;

26,"Linda",62;

0,0,0;

0,0,0;

0,0,0;

0,0,0;

0,0,0;

0,0,0},

{89,"Charles",24;

27,"Tina",45;

26,"Laura",62;

0,0,0;

0,0,0;

0,0,0;

0,0,0;

0,0,0;

0,0,0},

{101,"Ted",21;

203,"Jennifer",24;

105,"Marge",45;

201,"Doris",65;

106,"Meghan",34;

0,0,0;

0,0,0;

0,0,0;

0,0,0}

and returns

{89,"Charles",19;

27,"Tina",45;

26,"Linda",62;

0,0,0;

0,0,0;

0,0,0;

0,0,0;

0,0,0;

0,0,0;

89,"Charles",24;

27,"Tina",45;

26,"Laura",62;

0,0,0;

0,0,0;

0,0,0;

0,0,0;

0,0,0;

0,0,0;

101,"Ted",21;

203,"Jennifer",24;

105,"Marge",45;

201,"Doris",65;

106,"Meghan",34;

0,0,0;

0,0,0;

0,0,0;

0,0,0}

#### Step 2 - Remove empty rows

The FILTER function filters values based on a condition or criteria.

FILTER(*array*, *include*, [*if_empty*])

FILTER(VSTACK('1:3'!A2:C10),VSTACK('1:3'!A2:A10)<>"")

returns

{89,"Charles",19;

27,"Tina",45;

26,"Linda",62;

89,"Charles",24;

27,"Tina",45;

26,"Laura",62;

101,"Ted",21;

203,"Jennifer",24;

105,"Marge",45;

201,"Doris",65;

106,"Meghan",34}

### Functions in 'Array manipulation' category

The VSTACK function function is one of many functions in the 'Array manipulation' category.

## How to comment

How to add a formula to your comment<code>Insert your formula here.</code>

Convert less than and larger than signsUse html character entities instead of less than and larger than signs.

< becomes < and > becomes >

How to add VBA code to your comment[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

How to add a picture to your comment:Upload picture to postimage.org or imgur

Paste image link to your comment.

Contact OscarYou can contact me through this contact form