HomeGoogle DocsSpreadsheetRemove Extra Blank Cells in ArrayFormula Output at the Bottom

Remove Extra Blank Cells in ArrayFormula Output at the Bottom

Published on

If you choose criteria in multiple rows in functions like Vlookup, Sumif, etc. then you must want to know how to remove extra blank cells in ArrayFormula output. As the use of criteria in infinite range may return extra blank cells at the bottom of your formula output.

This cause one major issue. Even if the cells seem blank below the output, not below entire row, when you enter any value in any of those cells, the formula would return an #REF! error.

You May Like: Different Error Types in Google Sheets and How to Correct It.

In the below SUMIF formula in G2, I have the criteria in the range F2:F3. But in the SUMIF I have chosen F2:F. See the above-said issue surfacing when I enter a value below.

Remove Extra Blank Cells in ArrayFormula Output

Before addressing the issue of removing extra blank rows in ArrayFormula output, we must know how this happens.

The Reason for Extra Blank Cells in ArrayFormula Output at the Bottom

With the help of SUMIF, I am going to explain this. This will be applicable to other formulas too. See the SUMIF formula that is in use in cell G2.

Must Check: Google Sheets Functions Guide.

=ArrayFormula(if(len(F2:F),(sumif(B2:B,F2:F,C2:C)),))

Why I have used the below formula in SUMIF?

if(len(F2:F)

See what happens when I am not using the above in SUMIF.

sumif array with extra 0s

Actually, there is no criteria in F4:F. But the SUMIF treats this range contains criteria which are blank and sums the column C accordingly.

How to Remove Blank Cells in Criteria Range

To remove the blank cells in the criteria range (not in the formula output), you can use either IF+LEN combination or IF+ISBLANK combination.

You have already seen the IF+LEN combination in SUMIF. Below is the equivalent IF+ISBLANK combination.

=ArrayFormula(if(isblank(F2:F),"",(sumif(B2:B,F2:F,C2:C))))

The root cause of the issue that I have mentioned in the title is associated with this IF+LEN or IF+ISBLANK combo. This combo helps us to restrict the formula output visually in cells that contain the criteria. But unfortunately returns blank cells below the output.

If you ask me how to remove extra blank cells in ArrayFormula output, my answer is it’s formula specific.

Here are few formula examples starting with the above SUMIF.

How to Remove Blank Cells in ArrayFormula Output

I am including a few formula examples that cover some of the popular functions.

Remove Extra Blank Cells in SUMIF in Google Sheet

I am using the function Filter to filter out blank cells in the criteria that cause the extra zeroes and ultimately the blank cells.

=ArrayFormula(sumif(B2:B,filter(F2:F,F2:F<>""),C2:C))

In this make sure that you are not leaving any blank cells in between the selected criteria range.

Remove Extra Blank Cells in Vlookup in Google Sheets

The Vlookup returns #N/A instead of blank cells below the formula output. Here normally we use IFERROR to convert those #N/A errors to blank values.

=iferror(ArrayFormula(vlookup(E2:E9,A2:C9,2,FALSE)))
vlookup with n/a errors

Here again, we can use the Filter to remove the blank cells below the formula output.

=ArrayFormula(vlookup(FILTER(E2:E,E2:E<>""),A1:C,2,FALSE))

The Filter function won’t work in all scenarios. Here are such few examples and solutions.

Remove Extra Blank Cells in Row ArrayFormula Output at the Bottom

As you may know, the ROW function can fill a column with sequential numbers.

As an example;

=ArrayFormula(row(A1:A10))

This formula would return the sequential number from 1 to 10 in a column.

You can incorporate the IF+LEN combination with this formula too.

This Row formula would also return extra blank cells from cell A8 onwards. Here we can use Query or Sortn to remove the extra blank cells below the output.

=Query(ArrayFormula(if(len(B2:B),row(B1:B),)),"Select * where Col1 is not null",0)

The use of SORTN is tricky to remove the extra blank cells. It’s easy to use but it sorts the formula output. So if you are not concerned about sorting, use the SORTN to remove the extra blank cells below the output.

Here is the SORTN based formula.

=sortn(if(len(B2:B),row(B1:B),),max(if(len(B2:B),row(B1:B),),0))

This Sortn will limit the number of rows to the max output of Row function which is 6. That means there would be values in 6 cells in the row function output and that serve the purpose.

Tips to Eliminate Extra Rows in the Data Range Itself

Functions like SORT, UNIQUE don’t take criteria. To eliminate blank cells or rows below such formula outputs we can follow the below tip.

Here I am considering the UNIQUE function for example.

eliminate blank cells/rows in Unique/SORT etc.

Steps:

Filter the source data to eliminate the blank cells/rows at the bottom.

=filter(A1:A,len(A1:A))

Then use this as the source data in Unique.

=unique(filter(A1:A,len(A1:A)))

Conclusion:

In concise, there is no single formula that we can depend to remove extra blank cells in ArrayFormula output in Google Sheets.

In some cases, we can use Filter, and in some other cases, we can use Query or SORTN. What important is, in all combinations, the function LEN plays a vital role!

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.

Get Top N Values Using Excel’s FILTER Function

When using the FILTER function in Excel to extract the top N values, it's...

XLOOKUP in Excel: Working with Visible Rows in a Table

In Excel, the XLOOKUP function isn't inherently designed to exclusively work with visible rows;...

SUMPRODUCT Differences: Excel vs. Google Sheets

The core purpose of the SUMPRODUCT function remains consistent across both Excel and Google...

Sum Values by Month and Category in Excel

With the help of EOMONTH, UNIQUE, and SUMIFS functions in Excel, you can efficiently...

More like this

Interactive Random Task Assigner in Google Sheets

You have multiple tasks and multiple people. Here's a fun way to randomly assign...

Google Sheets Bar and Column Chart with Target Coloring

To color each data point in the column or bar chart according to the...

Analyzing Column A Between Non-Adjacent Values in Column B: Google Sheets

This tutorial addresses a common scenario encountered in Google Sheets: how to sum, average,...

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.