HomeGoogle DocsSpreadsheetVSTACK Function In Google Sheets (How To)

VSTACK Function In Google Sheets (How To)

Published on

When we use the VSTACK function in Google Sheets, we might see #N/A errors, blank cells, or blank rows in its output. How do we handle them?

In this Google Sheets tutorial, you can learn the function and also know how to remove those errors and blank rows.

VSTACK’s purpose is to append arrays vertically. It is also possible by placing ranges within open and closed Curly Brackets separated by a semicolon.

But the VSTACK function has the following advantages over the above Curly Bracket approach.

  1. It brings more readability to formulas.
  2. The width of arrays can be of different sizes. In such cases, you will see a #VALUE error when using the Curly Brackets.

You may find this function part of complex formulas in the future. So learning it’s essential now.

Syntax of the VSTACK Function in Google Sheets

Syntax: VSTACK(range1; [range2, …])

range1: The first array or range to append.

range2, … : Additional arrays or ranges (optional) to add to the previous range.

Basic Formula Examples

When you have an equal number of columns in ranges to append, you can use the VSTACK function or the Curly Brackets.

Here is an example in which we append the two ranges in Sheet1 and Sheet2 in a Google Sheets file.

Using Curly Brackets:

={Sheet1!A2:C10;Sheet2!A2:C15}

Using the VSTACK Function:

=vstack(Sheet1!A2:C10,Sheet2!A2:C15)

In the following example, the first range contains two columns, and the second one three columns. Here we can only use the VSTACK function to append them vertically.

VSTACK Function Example

The following VSTACK formula appends those arrays vertically.

=vstack(B3:C5,E3:G5)

While doing so, it finds which range, range1 or range2, contains the maximum number of columns and returns that many columns in the output.

So you may see #N/A errors in some cells. How do we remove them?

Replacing the #N/A in the VSTACK Result in Google Sheets

Since the number of columns in the range does not match, the above formula returns the default #N/A in some cells.

There is no pad_with argument similar to the WRAPCOLS or WRAPROWS functions in the VSTACK.

But we can use the IFERROR function to pad_with 0 (zero), blank, or some other values instead of the default value.

To replace #N/A in the VSTACK formula with zero, use the IFERROR as per the example below.

=iferror(vstack(B3:C5,E3:G5),0)

Using Query in VSTACK and Blank Row Issue

You may encounter one issue when you want to vertically stack multiple Query results using the VSTACK function in Google Sheets.

You may get one or more blank rows or rows full of #N/A between the appended result.

It happens when one or more Query formulas fail to return any value that matches the criterion.

How to remove blank or error rows in VSTACK in Google Sheets?

We can name the VSTACK formula using LET and filter out blank rows.

Here is an example.

Removing Blank Rows in VSTACK and QUERY

The range1, range2, and range3 are three Query formulas.

=vstack(query({B2:C6},"Select * where Col1='a'"),query({E2:F6},"Select * where Col1='b'"),query({H2:I6},"Select * where Col1='c'"))

The second Query returns blank since the condition evaluates to FALSE.

The VSTACK formula leaves a row filled with #N/A in that case. Of course, we cause IFERROR to pad with blank.

=iferror(vstack(query({B2:C6},"Select * where Col1='a'"),query({E2:F6},"Select * where Col1='b'"),query({H2:I6},"Select * where Col1='c'")))

But that may leave a blank row.

How to remove such blank rows in a VSTACK result in Google Sheets?

In the following formula, I’ve named the VSTACK with “blank” and filtered out the blank row.

=let(blanks,iferror(vstack(query({B2:C6},"Select * where Col1='a'"),query({E2:F6},"Select * where Col1='b'"),query({H2:I6},"Select * where Col1='c'"))),filter(blanks,index(blanks,0,1)<>""))

That’s all about how to use the VSTACK function in Google Sheets.

Thanks for the stay. Enjoy!

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Convert Month Name to Days in Google Sheets

We can utilize the EOMONTH, MONTH, DATE, and DAY functions in Google Sheets to...

Creating Custom Descending Sequence Lists in Excel

You can utilize functions like ROW or SEQUENCE in Excel to create a custom...

SUMIFS with XLOOKUP in Excel and Google Sheets

SUMIFS and SUMIF are infamous for producing an "argument must be a range" error...

Counting XLOOKUP Results with COUNTIFS in Excel and Google Sheets

We can use COUNTIF or COUNTIFS alongside an XLOOKUP formula to conditionally count the...

More like this

Convert Month Name to Days in Google Sheets

We can utilize the EOMONTH, MONTH, DATE, and DAY functions in Google Sheets to...

Appointment Schedule Template in Google Sheets

An appointment schedule template in Google Sheets can assist you in efficiently managing your...

Creating Sequential Dates in Equally Merged Cells in Google Sheets

Do you know how to create sequential dates in equally merged cells across a...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.