Excel checking if cell is empty

Excel for Microsoft 365 Excel for Microsoft 365 for Mac Excel 2021 Excel 2021 for Mac Excel 2019 Excel 2019 for Mac Excel 2016 Excel 2016 for Mac Excel 2013 Excel 2010 Excel 2007 Excel for Mac 2011 More…Less

Sometimes you need to check if a cell is blank, generally because you might not want a formula to display a result without input.

Formula in cell E2 is =IF(D2=1,"Yes",IF(D2=2,"No","Maybe"))

In this case we’re using IF with the ISBLANK function:

  • =IF(ISBLANK(D2),»Blank»,»Not Blank»)

Which says IF(D2 is blank, then return «Blank», otherwise return «Not Blank»). You could just as easily use your own formula for the «Not Blank» condition as well. In the next example we’re using «» instead of ISBLANK. The «» essentially means «nothing».

Checking if a cell is blank - Formula in cell E2 is =IF(ISBLANK(D2),"Blank","Not Blank")

=IF(D3=»»,»Blank»,»Not Blank»)

This formula says IF(D3 is nothing, then return «Blank», otherwise «Not Blank»). Here is an example of a very common method of using «» to prevent a formula from calculating if a dependent cell is blank:

  • =IF(D3=»»,»»,YourFormula())

    IF(D3 is nothing, then return nothing, otherwise calculate your formula).

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

How to check if a cell is empty or is not empty in Excel; this tutorial shows you a couple different ways to do this.

Sections:

Check if a Cell is Empty or Not — Method 1

Check if a Cell is Empty or Not — Method 2

Notes

Check if a Cell is Empty or Not — Method 1

Use the ISBLANK() function.

This will return TRUE if the cell is empty or FALSE if the cell is not empty.

Here, cell A1 is being checked, which is empty.

When the cell is not empty, it looks like this:

FALSE is output because cell B1 is not empty.

Reverse the True/False Output

Some formulas need to have TRUE or FALSE reversed in order to work correctly; to do this, use the NOT() function.

Result:

Whereas ISBLANK() output a TRUE for cell A1, the NOT() function reversed that and changed it to FALSE.

The same works for changing FALSE to TRUE.

Check if a Cell is Empty or Not — Method 2

You can also use an IF statement to check if a cell is empty.

=IF(A1="","Empty","Not Empty")

Result:

The function checks if this part is true: A1=»» which checks if A1 is equal to nothing.

When there is something in the cell, it works like this:

Cell B1 is not empty so we get a Not Empty result.

In this example I set the IF statement to output «Empty» or «Not Empty» but you can change it to whatever you like.

Reverse the Check

The example above checked if the cell was empty, but you can also check if the cell is not empty.

There are a few different ways to do this, but I will show you a simple and easy method here.

=IF(A1<>"","Not Empty","Empty")

Notice the check this time is A1<>»» and that says «is cell A1 not equal to nothing.» It sounds confusing but just remember that <> is basically the reverse of =.

I also had to switch the «Empty» and «Not Empty» in order to get the correct result since we are now checking if the cell is not empty.

Result:

As you can see, it outputs the same result as the previous example, just like it should.

Using <> instead of = merely reverses it, making a TRUE become a FALSE and a FALSE become a TRUE, which is why «Empty» and «Not Empty» had to be reversed in order to still output the correct result.

Notes

It may seem useless to return TRUE or FALSE like in the first method, but remember that many functions in Excel, including IF(), AND(), and OR() all rely on results that are either TRUE or FALSE.

Checking for blanks and returning TRUE or FALSE is a simple concept but it can get a bit confusing in Excel, especially when you have complex formulas that rely on the result of the formulas in this tutorial. Save this tutorial and work with the attached sample file and you will have it down in no time.

Make sure to download the attached sample file to work with these examples in Excel.

Similar Content on TeachExcel

Excel VBA Check if a Cell is in a Range

Tutorial: VBA that checks if a cell is in a range, named range, or any kind of range, in Excel.

Sec…

Make Complex Formulas for Conditional Formatting in Excel

Tutorial: How to make complex formulas for conditional formatting rules in Excel. This will serve as…

Sort Data Alphabetically or Numerically in Excel 2007 and Later

Tutorial: This Excel tip shows you how to Sort Data Alphabetically and Numerically in Excel 2007. T…

Filter Data to Display the Results that Begin With Specified Text or Words in Excel — AutoFilter

Macro: This Excel macro automatically filters a set of data based on the words or text that are c…

Odd or Even Row Formulas in Excel

Tutorial: Formulas to determine if the current cell is odd or even; this allows you to perform speci…

Formula to Count Occurrences of a Word in a Cell or Range in Excel

Tutorial: Formula to count how many times a word appears in a single cell or an entire range in Exce…

Subscribe for Weekly Tutorials

BONUS: subscribe now to download our Top Tutorials Ebook!

Home / Excel Formulas / IF Cell is Blank (Empty) using IF + ISBLANK

In Excel, if you want to check if a cell is blank or not, you can use a combination formula of IF and ISBLANK. These two formulas work in a way where ISBLANK checks for the cell value and then IF returns a meaningful full message (specified by you) in return.

In the following example, you have a list of numbers where you have a few cells blank.

Formula to Check IF a Cell is Blank or Not (Empty)

  1. First, in cell B1, enter IF in the cell.
  2. Now, in the first argument, enter the ISBLANK and refer to cell A1 and enter the closing parentheses.
  3. Next, in the second argument, use the “Blank” value.
  4. After that, in the third argument, use “Non-Blank”.
  5. In the end, close the function, hit enter, and drag the formula up to the last value that you have in the list.

As you can see, we have the value “Blank” for the cell where the cell is empty in column A.

=IF(ISBLANK(A1),"Blank","Non-Blank")

Now let’s understand this formula. In the first part where we have the ISBLANK which checks if the cells are blank or not.

And, after that, if the value returned by the ISBLANK is TRUE, IF will return “Blank”, and if the value returned by the ISBLANK is FALSE IF will return “Non_Blank”.

Alternate Formula

You can also use an alternate formula where you just need to use the IF function. Now in the function, you just need to specify the cell where you want to test the condition and then use an equal operator with the blank value to create a condition to test.

And you just need to specify two values that you want to get the condition TRUE or FALSE.

Download Sample File

  • Ready

And, if you want to Get Smarter than Your Colleagues check out these FREE COURSES to Learn Excel, Excel Skills, and Excel Tips and Tricks.

The logical expression =»» means «is empty». In the example shown, column D contains a date if a task has been completed. In column E, a formula checks for blank cells in column D. If a cell is blank, the result is a status of «Open». If the cell contains value (a date in this case, but it could be any value) the formula returns «Closed».

The effect of showing «Closed» in light gray is accomplished with a conditional formatting rule.

Display nothing if cell is blank

To display nothing if a cell is blank, you can replace the «value if false» argument in the IF function with an empty string («») like this:

=IF(D5="","","Closed")

Alternative with ISBLANK

Excel contains a function made to test for blank cells called ISBLANK. To use the ISBLANK, you can revise the formula as follows:

=IF(ISBLANK(D5),"Open","Closed")

You can use the following formulas to check if cells are empty in Excel:

Method 1: Check if One Cell is Empty

=IF(ISBLANK(A1),"Empty","Not Empty")

If cell A1 is empty, this formula returns “Empty” and if it’s not then the formula returns “Not Empty.”

Method 2: Check if Multiple Cells are Empty

=IF(AND(ISBLANK(A1), ISBLANK(B1)),"Empty","Not Empty")

If cells A1 and B1 are both empty, this formula returns “Empty.” Otherwise, it returns “Not Empty.”

The following examples show how to use each method in Excel.

Example 1: Check if One Cell is Empty

Suppose we have the following dataset in Excel that shows the number of points scored by various basketball players:

We’ll use the following formula to check if each cell in column A is empty:

=IF(ISBLANK(A2),"Empty","Not Empty") 

We’ll type this formula into cell B2 and then copy and paste it down to every remaining cell in column B:

Excel check if cell is empty

The values in column B tell us whether each corresponding value in column A is empty or not.

Example 2: Check if Multiple Cells are Empty

Suppose we have the following dataset in Excel:

We’ll use the following formula to check if the cell in both column A and column B are empty:

=IF(AND(ISBLANK(A2), ISBLANK(B2)),"Empty","Not Empty")

We’ll type this formula into cell C2 and then copy and paste it down to every remaining cell in column C:

Excel check if multiple cells are empty

The values in column C tell us whether or not both corresponding values in column A and column B are empty.

Additional Resources

The following tutorials explain how to perform other common tasks in Excel:

Excel: How to Check if Range Contains Specific Value
Excel: How to Check if Cell Contains Partial Text
Excel: How to Check if One Column Value Exists in Another Column

Содержание

  1. Examples of ISBLANK function for checking empty cells in Excel
  2. Examples of using ISBLANK function in Excel
  3. Why do you need to use ISBLANK function when checking empty cells
  4. Check for empty cell in Excel spreadsheet
  5. How to count the number of empty cells in Excel
  6. Features of the use of ISBLANK function in Excel
  7. If cell is not blank
  8. Related functions
  9. Summary
  10. Generic formula
  11. Explanation
  12. IF function
  13. ISBLANK function
  14. LEN function
  15. Excel: How to check if a cell is empty with VBA? [duplicate]
  16. 3 Answers 3
  17. Linked
  18. Related
  19. Hot Network Questions
  20. Excel ISBLANK function to check if cell is empty or not
  21. Excel ISBLANK function
  22. ISBLANK in Excel — things to remember
  23. How to use ISBLANK in Excel
  24. Excel formula: if cell is blank then
  25. Excel formula: if cell is not blank then
  26. If cell is blank, then leave blank
  27. If any cell in range is blank, then do something
  28. If all cells in range are blank, then do something
  29. Excel formula: if cell is not blank, then sum
  30. If not blank then sum
  31. If blank then sum
  32. Sum if all cells in range are not blank
  33. Excel formula: count if cell is not blank
  34. Excel ISBLANK not working
  35. Treat zero-length strings as blanks
  36. Remove or ignore extra spaces

Examples of ISBLANK function for checking empty cells in Excel

ISBLANK in Excel is used for the presence of textual, numeric, logical, and other types of data in the specified cell and returns a boolean value of TRUE if the cell is empty. If the specified cell contains any data, the result of executing the ISBLANK function is the logical value FALSE.

Examples of using ISBLANK function in Excel

Example 1. The Excel spreadsheet contains the results (points) for the exam, which was held in an educational institution. In this electronic statement, in front of some students, the grades are not indicated, because they were sent for retake. In the column next to display the text line «Passed» in front of those who were given marks, and «For rerun» — on the contrary, those who did not pass the first time.

Select the cells C3:C18 and write the following formula:

The formula IF validates the returned result of the ISBLANK function for a range of cells B3: B18 and returns one of the options («For rerun» or «Passed»). The result of the formula:

Now part of this formula can be used for conditional formatting:

  1. Select the range of cells C3: C18 and select the tool: “HOME”-“Styles”-“Conditional Formatting”-“New Rule”.
  2. In the “New Formatting Rule” window that appears, select the option: “Use formulas to determine which cells to format” and enter the following formula:
  3. Click on the “Format” button (as on the sample), then specify in the “Format of cells” red fill color and click OK on all open windows:

On against empty cells or twos, we receive a corresponding message “For rerun” and a red fill.

Why do you need to use ISBLANK function when checking empty cells

In the above example, you can change the formula using double quotation marks («») in place of the function of checking cells for emptiness, and it will also work:

=IF(OR( B3=»» ,B3=2),»For rerun»,»Passed»)

But not always! It all depends on the values that the cells may contain. Pay attention to how double quotes behave differently, and the function is ISBLANK if we have the same specific values in the cells:

As you can see in the picture in the cell is a single quote symbol. The first formula (with double quotes instead of a function) does not see it. Moreover, in the A1 cell itself, the single quote is not displayed because this special character in Excel is intended to display values in text format. This is convenient, for example, when we need to display the formula itself, and not the result of its calculation as done in cells D1 and D2. It is enough just to enter a single quote before the formula and now the formula itself is displayed, and not the returned result. But ISBLANK function sees that in fact the A1 cell is not empty!

Check for empty cell in Excel spreadsheet

Example 2. In the Excel spreadsheet recorded some data. Determine whether all fields are filled, or there is at least one field that is empty.

Source data table:

To determine if there are empty cells, use the following array formula (CTRL + SHIFT + Enter):

The SUM function is used to determine the sum of the values returned by the —ISBLANK function for each cell in the B3: B17 range (numeric values, since double negative is used). If the entry SUM(-BIDO(B3:B17) returns any value> 0, the IF function returns TRUE.

Result of calculations:

That is, in the range B3: B17 there is one or more empty cells.

Note: in the above formula, the characters «-» were used. This type of record is called double negation. In this case, double negation is needed to explicitly convert data of a logical type to numeric. Some Excel functions do not perform automatic data conversion, so the type conversion mechanism has to be started manually. The most common options for converting textual or logical values to a numeric type is multiplication by 1 or adding 0 (for example, = TRUE + 0 returns the number 1, or = «23» * 1 returns the number 23. However, using the record type = -TRUE speeds functions (according to some estimates, productivity gains up to 15%, which is important when processing large amounts of data).

How to count the number of empty cells in Excel

Example 3. Calculate the average age of office workers. If the table does not contain all the fields, display the corresponding message and do not perform the calculation.

Formula for calculation (array formula):

The IF function performs a range check for the presence of empty cells (expression SUM(—ISBLANK(B3:B12)). If the SUM returned a value> 0, a message will be displayed containing the number of empty data cells (COUNTBLANK) and the string “fields not filled in”, which are glued together with a “&” (concatenation operation).

Result of calculations:

Features of the use of ISBLANK function in Excel

ISBLANK function in Excel is among the logical functions (performing a check of some condition, for example, IF, ISREF, ISNUMBER, etc., and returning results in the form of data of logical type: TRUE, FALSE). Syntax function recording:

A single argument is required and can accept a reference to a cell or to a range of cells in which it is necessary to determine the presence of any data. If the function accepts a range of cells, the function should be used as an array formula.

  1. If a value was explicitly passed as an argument to the function (for example, =ISBLANK(TRUE), =ISBLANK(«text»), =ISBLANK(12)), the result of its execution is FALSE.
  2. If you want the function to return TRUE if the cell is not empty, you can use it with the NOT function. For example, = NOT(ISBLANK (A1)) returns TRUE if A1 is not empty.
  3. A record of type = ISBLANK(ADDRESS(x,y)) will always return false, because the ADDRESS(x,y) function returns a reference to a cell, that is, a non-empty value.
  4. The function returns the value FALSE even in cases where the cell passed in as an argument contains an error or a cell reference. This judgment is also valid for cases when, as a result of the execution of a formula, an empty line is displayed in the cell. For example, the formula =IF(2>1,»», FALSE) was entered in cell A1, which returns the empty string «». In this case, the function =ISBLANK(A1) returns the value FALSE.
  5. If you need to check several cells at once, you can use the function as an array formula (select the required number of empty cells, enter the formula «=ISBLANK(» and pass the range of the studied cells as an argument, use Ctrl + Shift + Enter as an argument)

Источник

If cell is not blank

Summary

To test if a cell is not blank (i.e. has content), you can use a formula based on the IF function. In the example shown, the formula in cell E5 is:

As the formula is copied down it returns «Done» when a cell in column D is not blank and an empty string («») if the cell is blank.

Generic formula

Explanation

In this example, the goal is to create a formula that will return «Done» in column E when a cell in column D contains a value. In other words, if the cell in column D is «not blank», then the formula should return «Done». In the worksheet shown, column D is is used to record the date a task was completed. Therefore, if the column contains a date (i.e. is not blank), we can assume the task is complete. This problem can be solved with the IF function alone or with the IF function and the ISBLANK function. It can also be solved with the LEN function. All three approaches are explained below.

IF function

The IF function runs a logical test and returns one value for a TRUE result, and another value for a FALSE result. You can use IF to test for a blank cell like this:

In the first example, we test if A1 is empty with =»». In the second example, the <> symbol is a logical operator that means «not equal to», so the expression A1<>«» means A1 is «not empty». In the worksheet shown, we use the second idea in cell E5 like this:

If D5 is «not empty», the result is «Done». If D5 is empty, IF returns an empty string («») which displays as nothing. As the formula is copied down, it returns «Done» only when a cell in column D contains a value. To display both «Done» and «Not done», you can adjust the formula like this:

ISBLANK function

Another way to solve this problem is with the ISBLANK function. The ISBLANK function returns TRUE when a cell is empty and FALSE if not. To use ISBLANK directly, you can rewrite the formula like this:

Notice the TRUE and FALSE results have been swapped. The logic now is if cell D5 is blank. To maintain the original logic, you can nest ISBLANK inside the NOT function like this:

The NOT function simply reverses the result returned by ISBLANK.

LEN function

One problem with testing for blank cells in Excel is that ISBLANK(A1) or A1=»» will both return FALSE if A1 contains a formula that returns an empty string. In other words, if a formula returns an empty string in a cell, Excel interprets the cell as «not empty». To work around this problem, you can use the LEN function to test for characters in a cell like this:

This is a much more literal formula. We are not asking Excel if A1 is blank, we are literally counting the characters in A1. The LEN function will return a positive number only when a cell contains actual characters.

Источник

Excel: How to check if a cell is empty with VBA? [duplicate]

Via VBA how can I check if a cell is empty from another with specific information?

If A:A = «product special» And B:B is null Then

Additionally, how can I use a For Each loop on the Range and how can I return the value in the other cell?

3 Answers 3

You could use IsEmpty() function like this:

you could also use following:

IsEmpty() would be the quickest way to check for that.

IsNull() would seem like a similar solution, but keep in mind Null has to be assigned to the cell; it’s not inherently created in the cell.

Also, you can check the cell by:

This site uses the method isEmpty() .

Edit: content grabbed from site, before the url will going to be invalid.

In the first step the data in the first column from Sheet1 will be sort. In the second step, all rows with same data will be removed.

Linked

Hot Network Questions

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.3.20.43330

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Excel ISBLANK function to check if cell is empty or not

by Svetlana Cheusheva, updated on March 14, 2023

The tutorial shows how to use ISBLANK and other functions to identify blank cells in Excel and take different actions depending on whether a cell is empty or not.

There are many situations when you need to check if a cell is empty or not. For instance, if cell is blank, then you might want to sum, count, copy a value from another cell, or do nothing. In these scenarios, ISBLANK is the right function to use, sometimes alone, but most often in combination with other Excel functions.

Excel ISBLANK function

The ISBLANK function in Excel checks whether a cell is blank or not. Like other IS functions, it always returns a Boolean value as the result: TRUE if a cell is empty and FALSE if a cell is not empty.

The syntax of ISBLANK assumes just one argument:

Where value is a reference to the cell you want to test.

For example, to find out if cell A2 is empty, use this formula:

To check if A2 is not empty, use ISBLANK together with the NOT function, which returns the reversed logical value, i.e. TRUE for non-blanks and FALSE for blanks.

Copy the formulas down to a few more cells and you will get this result:

ISBLANK in Excel — things to remember

The main point you should keep in mind is that the Excel ISBLANK function identifies truly empty cells, i.e. cells that contain absolutely nothing: no spaces, no tabs, no carriage returns, nothing that only appears blank in a view.

For a cell that looks blank, but in fact is not, an ISBLANK formula returns FALSE. This behavior occurs if a cell contains any of the following:

  • Formula that returns an empty string like IF(A1<>«», A1, «»).
  • Zero-length string imported from an external database or resulted from a copy/paste operation.
  • Spaces, apostrophes, non-breaking spaces ( ), linefeed or other non-printing characters.

How to use ISBLANK in Excel

To gain more understanding of what the ISBLANK function is capable of, let’s take a look at some practical examples.

Excel formula: if cell is blank then

Since Microsoft Excel does not have a built-in IFBLANK kind of function, you need to use IF and ISBLANK together to test a cell and perform an action if the cell is empty.

Here’s the generic version:

To see it in action, let’s check if a cell in column B (delivery date) has any value in it. If the cell is blank, then output «Open»; if the cell is not blank, then output «Completed».

=IF(ISBLANK(B2), «Open», «Completed»)

Please remember that the ISBLANK function only determines absolutely blank cells. If a cell contains something invisible to the human eye such as a zero-length string, ISBLANK would return FALSE. To illustrate this, please have a look at the screenshot below. The dates in column B are pulled from another sheet with this formula:

As the result, B4 and B6 contain empty strings («»). For these cells, our IF ISBLANK formula yields «Completed» because in terms of ISBLANK the cells are not empty.

If your classification of «blanks» includes cells containing a formula that results in an empty string, then use =»» for the logical test:

=IF(B2=»», «Open», «Completed»)

The screenshot below shows the difference:

Excel formula: if cell is not blank then

If you’ve closely followed the previous example and understood the formula’s logic, you should have no difficulties with modifying it for a specific case when an action shall only be taken when the cell is not empty.

Based on your definition of «blanks», choose one of the following approaches.

To identify only truly non-blank cells, reverse the logical value returned by ISBLANK by wrapping it into NOT:

Or use the already familiar IF ISBLANK formula (please notice that compared to the previous one, the value_if_true and value_if_false values are swapped):

To teat zero-length strings as blanks, use <>«» for the logical test of IF:

For our sample table, any of the below formulas will work a treat. They all will return «Completed» in column C if a cell in column B is not empty:

=IF(B2<>«», «Completed», «»)

If cell is blank, then leave blank

In certain scenarios, you may need a formula of this kind: If cell is blank do nothing, otherwise take some action. In fact, it’s nothing else but a variation of the generic IF ISBLANK formula discussed above, in which you supply an empty string («») for the value_if_true argument and the desired value/formula/expression for value_if_false.

For absolutely blank cells:

To regard empty strings as blanks:

In the table below, suppose you want to do the following:

  • If column B is empty, leave column C empty.
  • If column B contains a sales number, calculate the 10% commission.

To have it done, we multiply the amount in B2 by percentage and put the expression in the third argument of IF:

After copying the formula through column C, the result looks as follows:

If any cell in range is blank, then do something

In Microsoft Excel, there are a few different ways to check a range for empty cells. We will be using an IF statement to output one value if there is at least one empty cell in the range and another value if there are no empty cells at all. In the logical test, we calculate the total number of empty cells in the range, and then check if the count is greater than zero. This can be done with either COUNTBLANK or COUNTIF function:

Or a little bit more complex SUMPRODUCT formula:

For example, to assign the «Open» status to any project that has one or more blanks in columns B through D, you can use any of the below formulas:

=IF(SUMPRODUCT(—(B2:D2=»»))>0, «Open», «»)

Note. All these formulas treat empty strings as blanks.

If all cells in range are blank, then do something

To check if all cells in the range are empty, we will be using the same approach as in the above example. The difference is in the logical test of IF. This time, we count cells that are not empty. If the result is greater than zero (i.e. the logical test evaluates to TRUE), we know that not every cell in the range is blank. If the logical test is FALSE, that means all cells in the range are blank. So, we supply the desired value/expression/formula in the 3 rd argument of IF (value_if_false).

In this example, we will return «Not Started» for projects that have blanks for all the milestones in columns B through D.

The easiest way to count non-empty cells in Excel is by using the COUNTA function:

=IF(COUNTA(B2:D2)>0, «», «Not Started»)

Another way is COUNTIF for non-blanks («<>» as the criteria):

=IF(COUNTIF(B2:D2,»<>«)>0, «», «Not Started»)

Or the SUMPRODUCT function with the same logic:

=IF(SUMPRODUCT(—(B2:D2<>«»))>0, «», «Not Started»)

ISBLANK can also be used, but only as an array formula, which should be completed by pressing Ctrl + Shift + Enter , and in combination with the AND function. AND is needed for the logical test to evaluate to TRUE only when the result of ISBLANK for each cell is TRUE.

=IF(AND(ISBLANK(B2:D2)), «Not Started», «»)

Note. When choosing a formula for your worksheet, an important thing to consider is your understanding of «blanks». The formulas based on ISBLANK, COUNTA and COUNTIF with «<>» as the criteria look for absolutely empty cells. SUMPRODUCT also regards empty strings as blanks.

Excel formula: if cell is not blank, then sum

To sum certain cells when other cells are not blank, use the SUMIF function, which is especially designed for conditional sum.

In the table below, supposing you wish to find the total amount for the items that are already delivered and those that are not yet delivered.

If not blank then sum

To get the total of delivered items, check if the Delivery date in column B is not blank and if it isn’t, then sum the value in column C:

If blank then sum

To get the total of undelivered items, sum if the Delivery date in column B is blank:

=SUMIF(B2:B6, «», C2:C6)

Sum if all cells in range are not blank

To sum cells or perform some other calculation only when all cells in a given range are not blank, you can again use the IF function with the appropriate logical test.

For example, COUNTBLANK can bring us the total number of blanks in the range B2:B6. If the count is zero, we run the SUM formula; otherwise do nothing:

=IF(COUNTBLANK(B2:B6)=0, SUM(B2:B6), «»)

The same result can be achieved with an array IF ISBLANK SUM formula (please remember to press Ctrl + Shift + Enter to complete it correctly):

In this case, we use ISBLANK in combination with the OR function, so the logical test is TRUE if there is at least one blank cell in the range. Consequently, the SUM function goes to the value_if_false argument.

Excel formula: count if cell is not blank

As you probably know, Excel has a special function to count non-empty cells, the COUNTA function. Please be aware that the function counts cells containing any type of data, including the logical values of TRUE and FALSE, error, spaces, empty strings, etc.

For example, to count non-blank cells in the range B2:B6, this is the formula to use:

The same result can be achieved by using COUNTIF with the non-blank criteria («<>«):

To count blank cells, use the COUNTBLANK function:

=COUNTBLANK(B2:B6)

Excel ISBLANK not working

As already mentioned, ISBLANK in Excel returns TRUE only for really empty cells that contain absolutely nothing. For seemingly blank cells containing formulas that produce empty strings, spaces, apostrophes, non-printing characters, and the like, ISBLANK returns FALSE.

In a situation, when you want to treat visually empty cells as blanks, consider the following workarounds.

Treat zero-length strings as blanks

To consider cells with zero-length strings as blanks, in the logical test of IF, put either an empty string («») or the LEN function equal to zero.

=IF(A2=»», «blank», «not blank»)

=IF(LEN(A2)=0, «blank», «not blank»)

In case the ISBLANK function is malfunctioning because of blank spaces, the most obvious solution is to get rid of them. The following tutorial explains how to quickly remove leading, trailing and multiple in-between spaces, except for a single space character between words: How to remove extra spaces in Excel.

If for some reason removing excess spaces does not work for you, you can force Excel to ignore them.

To regard cells containing only space characters as empty, include LEN(TRIM(cell))=0 in the logical test of IF as an additional condition:

=IF(OR(A2=»», LEN(TRIM(A2))=0), «blank», «not blank»)

To ignore a specific non-printing character, find its code and supply it to the CHAR function.

For example, to identify cells containing empty strings and nonbreaking spaces ( ) as blanks, use the following formula, where 160 is the character code for a nonbreaking space:

=IF(OR(A2=»», A2=CHAR(160)), «blank», «not blank»)

That’s how to use the ISBLANK function to identify blank cells in Excel. I thank you for reading and hope to see you on our blog next week!

Источник

KEY PARAMETERS
Output Range: Select the output range by changing the cell reference («D5») in the VBA code.
Cell to Test: Select the cell that you want to check if it’s blank by changing the cell reference («C5») in the VBA code.
Worksheet Selection: Select the worksheet which captures the cells that you want to test if they are blank and return a specific value by changing the Analysis worksheet name in the VBA code. You can also change the name of this object variable, by changing the name ‘ws’ in the VBA code.
True and False Results: In this example if a cell is blank the VBA code will return a value of «No». If a cell is not blank the VBA code will return a value of «Yes». Both of these values can be changed to whatever value you desire by directly changing them in the VBA code.

NOTES
Note 1: If the cell that is being tested is returning a value of («») this VBA code will identify the cell as blank.
Note 2: If your True or False result is a text value it will need to be captured within quotation marks («»). However, if the result is a numeric value, you can enter it without the use of quotation marks.

KEY PARAMETERS
Output Range: Select the output range by changing the cell reference («D9») in the VBA code.
Cell to Test: Select the cell that you want to check if it’s blank by changing the cell reference («C9») in the VBA code.
Worksheet Selection: Select the worksheet which captures the cells that you want to test if they are blank and return a specific value by changing the Analysis worksheet name in the VBA code. You can also change the name of this object variable, by changing the name ‘ws’ in the VBA code.
True and False Results: In this example if a cell is blank the VBA code will return a value stored in cell C5. If a cell is not blank the VBA code will return a value stored in cell C6. Both of these values can be changed to whatever value you desire by either referencing to a different cell that captures the value that you want to return or change the values in those cells.

NOTES
Note 1: If the cell that is being tested is returning a value of («») this VBA code will identify the cell as blank.

KEY PARAMETERS
Output and Test Rows: Select the output rows and the rows that captures the cells that are to be tested by changing the x values (5 to 11). This example assumes that both the output and the associated test cell will be in the same row.
Test Column: Select the column that captures the cells that are to be tested by changing number 3, in ws.Cells(x, 3).
Output Column: Select the output column by changing number 4, in ws.Cells(x, 4).
Worksheet Selection: Select the worksheet which captures the cells that you want to test if they are blank and return a specific value by changing the Analysis worksheet name in the VBA code. You can also change the name of this object variable, by changing the name ‘ws’ in the VBA code.
True and False Results: In this example if a cell is blank the VBA code will return a value of «No». If a cell is not blank the VBA code will return a value of «Yes». Both of these values can be changed to whatever value you desire by directly changing them in the VBA code.

NOTES
Note 1: If the cell that is being tested is returning a value of («») this VBA code will identify the cell as blank.
Note 2: If your True or False result is a text value it will need to be captured within quotation marks («»). However, if the result is a numeric value, you can enter it without the use of quotation marks.

KEY PARAMETERS
Output and Test Rows: Select the output rows and the rows that captures the cells that are to be tested by changing the x values (9 to 15). This example assumes that both the output and the associated test cell will be in the same row.
Test Column: Select the column that captures the cells that are to be tested by changing number 3, in ws.Cells(x, 3).
Output Column: Select the output column by changing number 4, in ws.Cells(x, 4).
Worksheet Selection: Select the worksheet which captures the cells that you want to test if they are blank and return a specific value by changing the Analysis worksheet name in the VBA code. You can also change the name of this object variable, by changing the name ‘ws’ in the VBA code.
True and False Results: In this example if a cell is blank the VBA code will return a value stored in cell C5. If a cell is not blank the VBA code will return a value stored in cell C6. Both of these values can be changed to whatever value you desire by either referencing to a different cell that captures the value that you want to return or change the values in those cells.

NOTES
Note 1: If the cell that is being tested is returning a value of («») this VBA code will identify the cell as blank.

Looking for coding that checks if cell is empty or not. If it is not empty then move to the next cell group. But I need to check if the next cell group is empty or not. If not, then move to the next and so on.

My Current coding below.

If IsEmpty(ActiveSheet.Range("h3")) Then
    Do
    Checkbox1.Value = True
    Range("H3") = 17002
    Sheets("Sheet1").Range("I3") = Printerformat2.Text
Else
    Checkbox1.Value = True
    Range("l3") = 17002
    Sheets("Sheet1").Range("m3") = Printerformat2.Text
End If

Jean-François Corbett's user avatar

asked Aug 12, 2011 at 15:37

Jeremiah Sky S's user avatar

2

You need to use a for loop to iterate through the specified range in «H»

Dim i As Long
With ActiveSheet
  For i = 1 to 500

    If IsEmpty(.Range("h" & CStr(i)).Value) Then
     'Do 'Not sure where you're going with this one? This is not really needed from what I can tell.
     Checkbox1.Value = True
     .Range("H" & CStr(i)).Value = 17002
     Sheets("Sheet1").Range("I" & CStr(i)).Value = Printerformat2.Text
    Else
      Checkbox1.Value = True
      .Range("l" & CStr(i)) = 17002
      Sheets("Sheet1").Range("m" & CStr(i)).value = Printerformat2.Text
    End If

   Next
End With

Hope that helps?

answered Aug 13, 2011 at 1:23

Allen Gammel's user avatar

2

I think you should have a look at Range("your range").specialcells(xlCellTypeBlanks). This is the fastest way to loop through empty cells.
If you need to loop on non blank cells, you can check if your cell Intersect the empty cells range.

answered Aug 13, 2011 at 18:15

iDevlop's user avatar

iDevlopiDevlop

24.6k11 gold badges89 silver badges147 bronze badges

The most optimized way to make sure a cell is not empty is «If Len(cell) <> 0».

You can use .offset to access another cell in relation to it’s position from the current cell, or reference it directly, so you can check if it’s empty or not.

answered Aug 13, 2011 at 13:46

Gaijinhunter's user avatar

GaijinhunterGaijinhunter

14.5k4 gold badges50 silver badges57 bronze badges

Use

 Application.WorksheetFunction.isblank(ActiveSheet.range("h3"))

instead of

 IsEmpty(ActiveSheet.Range("h3")) 

Cordially

answered Aug 3, 2012 at 9:43

MUY Belgium's user avatar

MUY BelgiumMUY Belgium

2,2624 gold badges30 silver badges44 bronze badges

0

Excel VBA Tutorial about how to check if cell or range is empty with macros

In this VBA Tutorial, you learn how to check if a cell or range is empty.

This VBA Tutorial is accompanied by an Excel workbook containing the data and macros I use in the examples below. You can get immediate free access to this example workbook by subscribing to the Power Spreadsheets Newsletter.

Use the following Table of Contents to navigate to the section you’re interested in.

Related VBA and Macro Tutorials

The following VBA and Macro Tutorials may help you better understand and implement the contents below:

  • Learn about commonly-used VBA terms here.
  • Learn about the Excel Object Model and how to refer to objects here.
  • Learn how to create references to cell ranges here.
  • Learn how to declare and work with variables here.
  • Learn about data types here.
  • Learn how to work with worksheet functions within VBA here.

You can find additional VBA and Macro Tutorials in the Archives.

VBA Code to Check if Cell is Empty

To check if a cell is empty with VBA, use a macro with the following statement structure:

If IsEmpty(Cell) Then
    StatementsIfCellIsEmpty
Else
    StatementsIfCellIsNotEmpty
End If

Process Followed by VBA Code to Check if Cell is Empty

Check if Cell is empty > Execute StatementsIfCellIsEmpty or StatementsIfCellIsNotEmpty

VBA Statement Explanation

Line #1: If IsEmpty(Cell) Then

  1. Item: If… Then.
    • VBA Construct: Opening statement of If… Then… Else statement.
    • Description: The If… Then… Else statement conditionally executes a group of statements depending on the value of an expression. For these purposes:
      • The If… Then… Else statement tests the specified condition (IsEmpty(Cell)).
      • If the condition is met and returns True: StatementsIfCellIsEmpty are executed.
      • If the condition isn’t met and returns False: StatementsIfCellIsNotEmpty are executed.
  2. Item: IsEmpty(…).
    • VBA Construct: IsEmpty function.
    • Description: Generally, the IsEmpty function indicates whether a variable has been initialized. Nonetheless, you can also use IsEmpty to check if a cell is empty.

      The IsEmpty function:

      • Takes one parameter (expression) of the Variant data type. Within this macro structure, the parameter is a Range object (Cell).
      • Returns True if the variable is uninitialized or explicitly set to Empty. Otherwise, IsEmpty returns False.
  3. Item: Cell.
    • VBA Construct: Range object.
    • Description: Range object representing the cell you work with.

      You can usually return a Range object with constructs such as the Worksheet.Range, Worksheet.Cells (with the Range.Item) or Range.Offset properties. If you explicitly declare an object variable to represent Cell, use the Range object data type.

  4. Item: IsEmpty(Cell).
    • VBA Construct: Condition of If… Then… Else statement.
    • Description: This condition is an expression that evaluates to True or False. The IsEmpty function (IsEmpty(Cell)) returns True or False, as follows:
      • True: Cell is empty.
      • False: Cell is not empty.

Line #2: StatementsIfCellIsEmpty

  1. Item: StatementsIfCellIsEmpty.
    • VBA Construct: Statements within If… Then… Else statement.
    • Description: One or more VBA statements that are executed if the condition tested in the opening statement of the If… Then… Else statement (IsEmpty(Cell)) returns True. Within this macro structure, IsEmpty(Cell) returns True if Cell is empty.

Line #3: Else

  1. Item: Else.
    • VBA Construct: Else clause of If… Then… Else statement.
    • Description: The statements below the Else clause (StatementsIfCellIsNotEmpty) are executed if the condition tested in the opening statement of the If… Then… Else statement (IsEmpty(Cell)) returns False. Within this macro structure, IsEmpty(Cell) returns False if Cell is not empty.

Line #4: StatementsIfCellIsNotEmpty

  1. Item: StatementsIfCellIsNotEmpty.
    • VBA Construct: Else Statements within If… Then… Else statement.
    • Description: One or more VBA statements that are executed if the condition tested in the opening statement of the If… Then… Else statement (IsEmpty(Cell)) returns False. Within this macro structure, IsEmpty(Cell) returns False if Cell is not empty.

Line #5: End If

  1. Item: End If.
    • VBA Construct: Closing statement of If… Then… Else statement.
    • Description: The End If clause marks the end of the If… Then… Else block.

Macro Example to Check if Cell is Empty

The following macro example checks if cell A5 of the worksheet named “Check if Cell is Empty” (myCell) is empty and displays a message box confirming whether the cell is empty or not empty.

Sub checkIfCellIsEmpty()

    'Source: https://powerspreadsheets.com/
    'For further information: https://powerspreadsheets.com/excel-vba-cell-empty/

    'declare object variable to hold reference to cell you work with
    Dim myCell As Range

    'identify cell you work with
    Set myCell = ThisWorkbook.Worksheets("Check if Cell is Empty").Range("A5")

    'check if cell is empty. Depending on result, display message box indicating whether cell is empty (True) or not empty (False)
    If IsEmpty(myCell) Then
        MsgBox myCell.Address & " is empty"
    Else
        MsgBox myCell.Address & " is not empty"
    End If

End Sub

Effects of Executing Macro Example to Check if Cell is Empty

The following GIF illustrates the results of executing the macro example. Cell A5 (This cell isn’t empty) is not empty and the message box displayed confirms that this is the case.

Macro checks if cell is empty

#2: Check if Active Cell is Empty

VBA Code to Check if Active Cell is Empty

To check if the active cell is empty with VBA, use a macro with the following statement structure:

If IsEmpty(ActiveCell) Then
    StatementsIfActiveCellIsEmpty
Else
    StatementsIfActiveCellIsNotEmpty
End If

Process Followed by VBA Code to Check if Active Cell is Empty

Check if active cell is empty > Execute StatementsIfActiveCellIsEmpty or StatementsIfActiveCellIsNotEmpty

VBA Statement Explanation

Line #1: If IsEmpty(ActiveCell) Then

  1. Item: If… Then.
    • VBA Construct: Opening statement of If… Then… Else statement.
    • Description: The If… Then… Else statement conditionally executes a group of statements depending on the value of an expression. For these purposes:
      • The If… Then… Else statement tests the specified condition (IsEmpty(ActiveCell)).
      • If the condition is met and returns True: StatementsIfActiveCellIsEmpty are executed.
      • If the condition isn’t met and returns False: StatementsIfActiveCellIsNotEmpty are executed.
  2. Item: IsEmpty(…).
    • VBA Construct: IsEmpty function.
    • Description: Generally, the IsEmpty function indicates whether a variable has been initialized. Nonetheless, you can also use IsEmpty to check if a cell is empty.

      The IsEmpty function:

      • Takes one parameter (expression) of the Variant data type. Within this macro structure, the parameter is a Range object (ActiveCell).
      • Returns True if the variable is uninitialized or explicitly set to Empty. Otherwise, IsEmpty returns False.
  3. Item: ActiveCell.
    • VBA Construct: Application.ActiveCell property.
    • Description: The Application.ActiveCell property returns a Range object representing the active cell.
  4. Item: IsEmpty(ActiveCell).
    • VBA Construct: Condition of If… Then… Else statement.
    • Description: This condition is an expression that evaluates to True or False. The IsEmpty function (IsEmpty(ActiveCell)) returns True or False, as follows:
      • True: Active cell is empty.
      • False: Active cell is not empty.

Line #2: StatementsIfActiveCellIsEmpty

  1. Item: StatementsIfActiveCellIsEmpty.
    • VBA Construct: Statements within If… Then… Else statement.
    • Description: One or more VBA statements that are executed if the condition tested in the opening statement of the If… Then… Else statement (IsEmpty(ActiveCell)) returns True. Within this macro structure, IsEmpty(ActiveCell) returns True if the active cell is empty.

Line #3: Else

  1. Item: Else.
    • VBA Construct: Else clause of If… Then… Else statement.
    • Description: The statements below the Else clause (StatementsIfActiveCellIsNotEmpty) are executed if the condition tested in the opening statement of the If… Then… Else statement (IsEmpty(ActiveCell)) returns False. Within this macro structure, IsEmpty(ActiveCell) returns False if the active cell is not empty.

Line #4: StatementsIfActiveCellIsNotEmpty

  1. Item: StatementsIfActiveCellIsNotEmpty.
    • VBA Construct: Else Statements within If… Then… Else statement.
    • Description: One or more VBA statements that are executed if the condition tested in the opening statement of the If… Then… Else statement (IsEmpty(ActiveCell)) returns False. Within this macro structure, IsEmpty(ActiveCell) returns False if the active cell is not empty.

Line #5: End If

  1. Item: End If.
    • VBA Construct: Closing statement of If… Then… Else statement.
    • Description: The End If clause marks the end of the If… Then… Else block.

Macro Example to Check if Active Cell is Empty

The following macro example checks if the active cell is empty and displays a message box confirming whether the active cell is empty or not empty.

Sub checkIfActiveCellIsEmpty()

    'Source: https://powerspreadsheets.com/
    'For further information: https://powerspreadsheets.com/excel-vba-cell-empty/

    'check if active cell is empty. Depending on result, display message box indicating whether active cell is empty (True) or not empty (False)
    If IsEmpty(ActiveCell) Then
        MsgBox "The active cell is empty"
    Else
        MsgBox "The active cell is not empty"
    End If

End Sub

Effects of Executing Macro Example to Check if Active Cell is Empty

The following GIF illustrates the results of executing the macro example. The active cell (A6) is empty and the message box displayed confirms that this is the case.

Macro checks if active cell is empty

#3: Check if Range is Empty

VBA Code to Check if Range is Empty

To check if a range is empty with VBA, use a macro with the following statement structure:

If WorksheetFunction.CountA(CellRange) = 0 Then
    StatementsIfRangeIsEmpty
Else
    StatementsIfRangeIsNotEmpty
End If

Process Followed by VBA Code to Check if Range is Empty

Check if number of non-empty cells in range is 0 > Execute StatementsIfRangeIsEmpty or StatementsIfRangeIsNotEmpty

VBA Statement Explanation

Line #1: If WorksheetFunction.CountA(CellRange) = 0 Then

  1. Item: If… Then.
    • VBA Construct: Opening statement of If… Then… Else statement.
    • Description: The If… Then… Else statement conditionally executes a group of statements depending on the value of an expression. For these purposes:
      • The If… Then… Else statement tests the specified condition (WorksheetFunction.CountA(CellRange) = 0).
      • If the condition is met and returns True: StatementsIfRangeIsEmpty are executed.
      • If the condition isn’t met and returns False: StatementsIfRangeIsNotEmpty are executed.
  2. Item: WorksheetFunction.CountA(…).
    • VBA Construct: WorksheetFunction.CountA method.
    • Description: The WorksheetFunction.CountA method counts the number of cells that are not empty within the argument list (CellRange). For these purposes, a cell is deemed to not be empty if, for example, it contains an error value or empty text (“”).
  3. Item: CellRange.
    • VBA Construct: Range object.
    • Description: Range object representing the cell range you work with.

      You can usually return a Range object with constructs such as the Worksheet.Range property. If you explicitly declare an object variable to represent CellRange, use the Range object data type.

  4. Item: =.
    • VBA Construct: = comparison operator.
    • Description: The = comparison operator compares the 2 expressions to determine whether they’re equal:
      • The expression to the left of the = comparison operator (WorksheetFunction.CountA(CellRange)).
      • The expression to the right of the = comparison operator (0).
  5. Item: WorksheetFunction.CountA(CellRange) = 0.
    • VBA Construct: Condition of If… Then… Else statement.
    • Description: The condition is an expression that evaluates to True or False. The = comparison operator returns True or False as follows:
      • True: If WorksheetFunction.CountA(CellRange) returns 0. This occurs when CellRange is empty.
      • False: If WorksheetFunction.CountA(CellRange) returns a value other than 0. This occurs when CellRange isn’t empty.

Line #2: StatementsIfRangeIsEmpty

  1. Item: StatementsIfRangeIsEmpty.
    • VBA Construct: Statements within If… Then… Else statement.
    • Description: One or more VBA statements that are executed if the condition tested in the opening statement of the If… Then… Else statement (WorksheetFunction.CountA(CellRange) = 0) returns True. Within this macro structure, (WorksheetFunction.CountA(CellRange) = 0) returns True if CellRange is empty.

Line #3: Else

  1. Item: Else.
    • VBA Construct: Else clause of If… Then… Else statement.
    • Description: The statements below the Else clause (StatementsIfRangeIsNotEmpty) are executed if the condition tested in the opening statement of the If… Then… Else statement (WorksheetFunction.CountA(CellRange) = 0) returns False. Within this macro structure, (WorksheetFunction.CountA(CellRange) = 0) returns False if CellRange is not empty.

Line #4: StatementsIfRangeIsNotEmpty

  1. Item: StatementsIfRangeIsNotEmpty.
    • VBA Construct: Else Statements within If… Then… Else statement.
    • Description: One or more VBA statements that are executed if the condition tested in the opening statement of the If… Then… Else statement (WorksheetFunction.CountA(CellRange) = 0) returns False. Within this macro structure, (WorksheetFunction.CountA(CellRange) = 0) returns False if CellRange is not empty.

Line #5: End If

  1. Item: End If.
    • VBA Construct: Closing statement of If… Then… Else statement.
    • Description: The End If clause marks the end of the If… Then… Else block.

Macro Example to Check if Range is Empty

The following macro example checks if the range composed of cells A7 through A11 of the worksheet named “Check if Cell is Empty” (myCellRange) is empty and displays a message box confirming whether the range is empty or not empty.

Sub checkIfRangeIsEmpty()

    'Source: https://powerspreadsheets.com/
    'For further information: https://powerspreadsheets.com/excel-vba-cell-empty/

    'declare object variable to hold reference to cell range you work with
    Dim myCellRange As Range

    'identify cell range you work with
    Set myCellRange = ThisWorkbook.Worksheets("Check if Cell is Empty").Range("A7:A11")

    'check if number of non-empty cells in range is 0. Depending on result, display message box indicating whether cell range is empty (True) or not empty (False)
    If WorksheetFunction.CountA(myCellRange) = 0 Then
        MsgBox myCellRange.Address & " is empty"
    Else
        MsgBox myCellRange.Address & " is not empty"
    End If

End Sub

Effects of Executing Macro Example to Check if Range is Empty

The following GIF illustrates the results of executing the macro example. Cells A7 through A11 (with fill) are empty and the message box displayed confirms that this is the case.

Macro checks if range is empty

#4: Check if Any Cell in Range is Empty

VBA Code to Check if Any Cell in Range is Empty

To check if any cell in a range is empty with VBA, use a macro with the following statement structure:

If WorksheetFunction.CountA(CellRange) < CellRange.Count Then
    StatementsIfAnyCellInRangeIsEmpty
Else
    StatementsIfNoCellInRangeIsEmpty
End If

Process Followed by VBA Code to Check if Any Cell in Range is Empty

Check if number of non-empty cells in range is less than total number of cells in range > Execute StatementsIfAnyCellInRangeIsEmpty or StatementsIfNoCellInRangeIsEmpty

VBA Statement Explanation

Line #1: If WorksheetFunction.CountA(CellRange) < CellRange.Count Then

  1. Item: If… Then.
    • VBA Construct: Opening statement of If… Then… Else statement.
    • Description: The If… Then… Else statement conditionally executes a group of statements depending on the value of an expression. For these purposes:
      • The If… Then… Else statement tests the specified condition (WorksheetFunction.CountA(CellRange) < CellRange.Count).
      • If the condition is met and returns True: StatementsIfAnyCellInRangeIsEmpty are executed.
      • If the condition isn’t met and returns False: StatementsIfNoCellInRangeIsEmpty are executed.
  2. Item: WorksheetFunction.CountA(…).
    • VBA Construct: WorksheetFunction.CountA method.
    • Description: The WorksheetFunction.CountA method counts the number of cells that are not empty within the argument list (CellRange). For these purposes, a cell is deemed to not be empty if, for example, it contains an error value or empty text (“”).
  3. Item: CellRange.
    • VBA Construct: Range object.
    • Description: Range object representing the cell range you work with.

      You can usually return a Range object with constructs such as the Worksheet.Range property. If you explicitly declare an object variable to represent CellRange, use the Range object data type.

  4. Item: <.
    • VBA Construct: < comparison operator.
    • Description: The < comparison operator compares 2 expressions to determine whether (i) the expression to its left (WorksheetFunction.CountA(CellRange)), (ii) is less than (iii) the expression to its right (CellRange.Count).
  5. Item: CellRange.Count.
    • VBA Construct: Range.Count property.
    • Description: The Range.Count property returns the number of objects in the collection (CellRange). Within this macro structure, the Count property returns the number of individual cells within CellRange.
  6. Item: WorksheetFunction.CountA(CellRange) < CellRange.Count.
    • VBA Construct: Condition of If… Then… Else statement.
    • Description: The condition is an expression that evaluates to True or False. The < comparison operator returns True or False as follows:
      • True: If WorksheetFunction.CountA(CellRange) returns a value smaller than the value returned by CellRange.Count. Within this macro structure, this occurs when (i) the number of non-empty cells in CellRange (returned by WorksheetFunction.CountA(CellRange)) (ii) is less than (iii) the number of cells in CellRange (returned by CellRange.Count). This occurs when CellRange contains at least 1 empty cell.
      • False: If WorksheetFunction.CountA(CellRange) returns a value equal to the value returned by CellRange.Count. Within this macro structure, this occurs when (i) the number of non-empty cells in CellRange (returned by WorksheetFunction.CountA(CellRange)) (ii) is equal to (iii) the number of cells in CellRange (returned by CellRange.Count). This occurs when CellRange contains no empty cells.

Line #2: StatementsIfAnyCellInRangeIsEmpty

  1. Item: StatementsIfAnyCellInRangeIsEmpty.
    • VBA Construct: Statements within If… Then… Else statement.
    • Description: One or more VBA statements that are executed if the condition tested in the opening statement of the If… Then… Else statement (WorksheetFunction.CountA(CellRange) < CellRange.Count) returns True. Within this macro structure, (WorksheetFunction.CountA(CellRange) < CellRange.Count) returns True if CellRange contains at least 1 empty cell.

Line #3: Else

  1. Item: Else.
    • VBA Construct: Else clause of If… Then… Else statement.
    • Description: The statements below the Else clause (StatementsIfNoCellInRangeIsEmpty) are executed if the condition tested in the opening statement of the If… Then… Else statement (WorksheetFunction.CountA(CellRange) < CellRange.Count) returns False. Within this macro structure, (WorksheetFunction.CountA(CellRange) < CellRange.Count) returns False if CellRange doesn’t contain any empty cells.

Line #4: StatementsIfNoCellInRangeIsEmpty

  1. Item: StatementsIfNoCellInRangeIsEmpty.
    • VBA Construct: Else Statements within If… Then… Else statement.
    • Description: One or more VBA statements that are executed if the condition tested in the opening statement of the If… Then… Else statement (WorksheetFunction.CountA(CellRange) < CellRange.Count) returns False. Within this macro structure, (WorksheetFunction.CountA(CellRange) < CellRange.Count) returns False if CellRange doesn’t contain any empty cells.

Line #5: End If

  1. Item: End If.
    • VBA Construct: Closing statement of If… Then… Else statement.
    • Description: The End If clause marks the end of the If… Then… Else block.

Macro Example to Check if Any Cell in Range is Empty

The following macro example checks if the range composed of cells A13 through A17 of the worksheet named “Check if Cell is Empty” (myCellRange) contains any empty cells and displays a message box confirming whether the range contains or not any empty cells.

Sub checkIfAnyCellInRangeIsEmpty()

    'Source: https://powerspreadsheets.com/
    'For further information: https://powerspreadsheets.com/excel-vba-cell-empty/

    'declare object variable to hold reference to cell range you work with
    Dim myCellRange As Range

    'identify cell range you work with
    Set myCellRange = ThisWorkbook.Worksheets("Check if Cell is Empty").Range("A13:A17")

    'check if number of non-empty cells in range is less than total number of cells in range. Depending on result, display message box indicating whether cell range contains any empty cell (True) or not (False)
    If WorksheetFunction.CountA(myCellRange) < myCellRange.Count Then
        MsgBox myCellRange.Address & " contains at least 1 empty cell"
    Else
        MsgBox myCellRange.Address & " doesn't contain empty cells"
    End If

End Sub

Effects of Executing Macro Example to Check if Any Cell in Range is Empty

The following GIF illustrates the results of executing the macro example. Cell A15 is empty. The message box displayed confirms that the cell range containing cells A13 to A17 (with fill) contains at least one empty cell (A15).

Macro checks if any cell in range is empty

References to VBA Constructs Used in this VBA Tutorial

Use the following links to visit the appropriate webpage within the Microsoft Developer Network:

  1. Identify the cell or cell range you work with:
    • Workbook object.
    • Application.ThisWorkbook property.
    • Worksheet object.
    • Workbook.Worksheets property.
    • Range object.
    • Worksheet.Range property.
    • Worksheet.Cells property.
    • Range.Item property.
    • Range.Offset property.
    • Application.ActiveCell property.
  2. Test if a cell or cell range is empty:
    • If… Then… Else statement.
    • IsEmpty function.
    • WorksheetFunction.CountA method.
    • Range.Count property.
    • Comparison operators.
  3. Display a message box including, among others, the address of a cell or cell range:
    • MsgBox function.
    • Range.Address property.
    • & operator.
  4. Work with variables and data types:
    • Dim statement.
    • Set statement.
    • = operator.
    • Data types:
      • Boolean data type.
      • String data type.
      • Variant data type.

Like this post? Please share to your friends:
  • Excel check if value is in range
  • Excel check if value in cell
  • Excel check if not error
  • Excel check if a cell is not empty
  • Excel check for value