Что такое empty cell в excel

Excel for Microsoft 365 Word for Microsoft 365 Outlook for Microsoft 365 PowerPoint for Microsoft 365 Excel 2021 Word 2021 Outlook 2021 PowerPoint 2021 Excel 2019 Word 2019 Outlook 2019 PowerPoint 2019 Excel 2016 Word 2016 Outlook 2016 PowerPoint 2016 Excel 2013 Word 2013 Outlook 2013 PowerPoint 2013 Excel 2010 Word 2010 Outlook 2010 PowerPoint 2010 Excel 2007 Word 2007 Outlook 2007 PowerPoint 2007 More…Less

By default, data that is hidden in rows and columns in the worksheet is not displayed in a chart, and empty cells or null values are displayed as gaps. For most chart types, you can display the hidden data in a chart.

For line, scatter, and radar chart types, you can also change the way that empty cells, and cells that display the #N/A error are displayed in the chart. Instead of displaying empty cells as gaps, you can display empty cells as zero values (0), or you can span the gaps with a line. For #N/A values, you can choose to display those as an empty cell or connect data points with a line. The following examples show Excel’s behavior with each of these options.

Options for showing empty cells

Options for cells with #N/A

#N/A in Day 4's cell, chart showing a gap in the line

#N/A in Day 4's cell, chart showing a connection across Day 4

Change the way that empty cells, null (#N/A) values, and hidden rows and columns are displayed in a chart

  1. Click the chart you want to change.

  2. Go to Chart Tools on the Ribbon, then on the Design tab, in the Data group, click Select Data.

    Excel Ribbon Image

  3. Click Hidden and Empty Cells.

    Excel Charting dialog for Hidden and Empty Cells

  4. In the Show empty cells as: options box, click Gaps, Zero, or Connect data points with line.

    Note: On a scatter chart that displays only markers (without connecting lines), you can display empty cells as gaps or zero only — you cannot connect the data points with a line.

  5. Click the Show #N/A as an empty cell option if you don’t want Excel to plot those points.

    Your browser does not support video. Install Microsoft Silverlight, Adobe Flash Player, or Internet Explorer 9.

    Notes: 

    • In order to maintain backwards compatibility with other versions of Excel, this feature is off by default.

  6. Click the Show data in hidden rows and columns option if you want Excel to plot hidden data.

Top of Page

Need more help?

You can always ask an expert in the Excel Tech Community, get support in the Answers community, or suggest a new feature or improvement. see How do I give feedback on Microsoft Office? to learn how to share your thoughts. We’re listening.

Related Topics

Create a chart from start to finish

Need more help?

Содержание

  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!

Источник

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!

Two pet peeves of mine are the way the terms [unique and distinct] and [empty and blank] are interchangeably used in Excel. They have different meanings so it’s really confusing when the name of a function or utility suggests it will do one thing when, in fact, it does the other.

I’ve defined unique and distinct on previous posts such as this one, so I’ll put those to one side and concentrate today’s rant post on empty and blank. Before I highlight the inconsistencies between ISBLANK() , COUNTBLANK() and VBA.IsEmpty() , here are my definitions of empty and blank cells:

  • An empty cell can be defined as a cell that contains absolutely nothing: no constant, no formula and no prefix character.
  • A blank cell can be defined as a cell which may be empty, or may contain a prefix character or a null string (formula result or constant).

Note that the formatting is ignored. These definitions are just my own – so please don’t take them as gospel – but they’re based on the behaviour of VBA.IsEmpty() and COUNTBLANK().

Is A Cell Empty?

In a worksheet, the best way to check is a cell is empty is to use the ISBLANK() worksheet function:

ISBLANK_1

Row 3 indicates what is in the corresponding column in row 4.

The Range.Value and Range.Value2 properties return a Variant/Empty when the given cell is empty, so the best way to check if a cell is empty in VBA is to use the VBA.Information.IsEmpty() function on their output:

Sub foo()

    Debug.Print IsEmpty(Sheet1.Range("A4").Value2)   'False
    Debug.Print IsEmpty(Sheet1.Range("B4").Value2)   'False
    Debug.Print IsEmpty(Sheet1.Range("C4").Value2)   'False
    Debug.Print IsEmpty(Sheet1.Range("D4").Value2)   'True

End Sub

The ISBLANK() worksheet function and VBA.IsEmpty() give exactly the same results so, unless one considers blank and empty to mean the same thing, they’re obviously inconsistently named. By my own definition, ISBLANK() should’ve been called ISEMPTY(). It’s worth mentioning that the ISBLANK() worksheet function isn’t available in VBA via the Application.WorksheetFunction class: presumably because Microsoft recognised that its functionality was already covered by VBA.IsEmpty() which is faster to call from VBA.

Is A Cell Blank?

The COUNTBLANK() worksheet function does not behave in a consistent manner with its ISBLANK() counterpart. COUNTBLANK() will count empty cells, cells with a null string and cells which contain a prefix character. Yeah, I know, it’s pretty confusing.  The upside is we can use COUNTBLANK() to check if a cell is actually blank:

COUNTBLANK_1

An easy way to check if a cell is blank from VBA is to call the Range.Value (or Range.Value2) property and compare the result to the VBA.Constants.vbNullString constant:

Sub foo()

    Debug.Print IsBlank(Sheet1.Range("A4"))  'False
    Debug.Print IsBlank(Sheet1.Range("B4"))  'True
    Debug.Print IsBlank(Sheet1.Range("C4"))  'True
    Debug.Print IsBlank(Sheet1.Range("D4"))  'True

End Sub

Public Function IsBlank(ByRef rngToCheck As Range) As Boolean
    IsBlank = (CStr(rngToCheck.Cells(1).Value2) = vbNullString)
End Function

It’s more efficient within VBA to do it this way than to call the Application.WorksheetFunction.CountBlank() method.

Does A Cell Contain A Null String?

I’ve mentioned null strings a few times so I better explain what they are. A null string is a zero-length string that could be a constant or the result of a formula. For example, this formula returns a null string:

=""

If you copy that formula and paste special values then the cell will contain a constant null string. You can also sometimes get null strings when you import data from an external source, so they’re worth knowing about.

The HasNullString() function below will return True if a cell contains a null string. If you want formula results to be ignored (ie. check for constants only) then pass True into the blnConstantsOnly parameter . If the cell has a prefix character then the function will return False.

Public Function HasNullString( _
                ByRef rngToCheck As Range, _
                Optional ByVal blnConstantsOnly As Boolean = False _
                            ) As Boolean

    Dim rngFirstCell As Range
    Dim strToCheck As String
    Dim varToCheck As Variant

    Set rngFirstCell = rngToCheck.Cells(1)
    varToCheck = rngFirstCell.Value2

    If Not IsEmpty(varToCheck) Then

        If blnConstantsOnly Then
            strToCheck = rngFirstCell.Formula
        Else
            strToCheck = CStr(varToCheck)
        End If

        If strToCheck = vbNullString Then
            HasNullString = (LenB(rngFirstCell.PrefixCharacter) = 0)
        End If

    End If

End Function

So, am I just being an old fuddy-duddy or do these inconsistencies annoy you too?

Excel does not have any way to do this.

The result of a formula in a cell in Excel must be a number, text, logical (boolean) or error. There is no formula cell value type of «empty» or «blank».

One practice that I have seen followed is to use NA() and ISNA(), but that may or may not really solve your issue since there is a big differrence in the way NA() is treated by other functions (SUM(NA()) is #N/A while SUM(A1) is 0 if A1 is empty).

answered Jul 13, 2009 at 14:09

Joe Erickson's user avatar

Joe EricksonJoe Erickson

7,0591 gold badge31 silver badges31 bronze badges

6

You’re going to have to use VBA, then. You’ll iterate over the cells in your range, test the condition, and delete the contents if they match.

Something like:

For Each cell in SomeRange
  If (cell.value = SomeTest) Then cell.ClearContents
Next

brettdj's user avatar

brettdj

54.6k16 gold badges113 silver badges176 bronze badges

answered Jul 13, 2009 at 18:08

J.T. Grimes's user avatar

J.T. GrimesJ.T. Grimes

4,2141 gold badge27 silver badges32 bronze badges

10

Yes, it is possible.

It is possible to have a formula returning a trueblank if a condition is met. It passes the test of the ISBLANK formula. The only inconvenience is that when the condition is met, the formula will evaporate, and you will have to retype it. You can design a formula immune to self-destruction by making it return the result to the adjacent cell. Yes, it is also possible.

enter image description here

All you need is to set up a named range, say GetTrueBlank, and you will be able to use the following pattern just like in your question:

=IF(A1 = "Hello world", GetTrueBlank, A1)

Step 1. Put this code in Module of VBA.

Function Delete_UDF(rng)
    ThisWorkbook.Application.Volatile
    rng.Value = ""
End Function

Step 2. In Sheet1 in A1 cell add named range GetTrueBlank with the following formula:

=EVALUATE("Delete_UDF("&CELL("address",Sheet1!A1)&")")

enter image description here

That’s it. There are no further steps. Just use self-annihilating formula. Put in the cell, say B2, the following formula:

=IF(A2=0,GetTrueBlank,A2)

The above formula in B2 will evaluate to trueblank, if you type 0 in A2.

You can download a demonstration file here.

In the example above, evaluating the formula to trueblank results in an empty cell. Checking the cell with ISBLANK formula results positively in TRUE. This is hara-kiri. The formula disappears from the cell when a condition is met. The goal is reached, although you probably might want the formula not to disappear.

You may modify the formula to return the result in the adjacent cell so that the formula will not kill itself. See how to get UDF result in the adjacent cell.

adjacent cell

I have come across the examples of getting a trueblank as a formula result revealed by The FrankensTeam here:
https://sites.google.com/site/e90e50/excel-formula-to-change-the-value-of-another-cell

answered Sep 6, 2016 at 14:22

Przemyslaw Remin's user avatar

Przemyslaw ReminPrzemyslaw Remin

6,09624 gold badges108 silver badges186 bronze badges

4

Maybe this is cheating, but it works!

I also needed a table that is the source for a graph, and I didn’t want any blank or zero cells to produce a point on the graph. It is true that you need to set the graph property, select data, hidden and empty cells to «show empty cells as Gaps» (click the radio button). That’s the first step.

Then in the cells that may end up with a result that you don’t want plotted, put the formula in an IF statement with an NA() results such as =IF($A8>TODAY(),NA(), *formula to be plotted*)

This does give the required graph with no points when an invalid cell value occurs. Of course this leaves all cells with that invalid value to read #N/A, and that’s messy.

To clean this up, select the cell that may contain the invalid value, then select conditional formatting — new rule. Select ‘format only cells that contain’ and under the rule description select ‘errors’ from the drop down box. Then under format select font — colour — white (or whatever your background colour happens to be). Click the various buttons to get out and you should see that cells with invalid data look blank (they actually contain #N/A but white text on a white background looks blank.) Then the linked graph also does not display the invalid value points.

Honza Zidek's user avatar

Honza Zidek

8,7914 gold badges70 silver badges110 bronze badges

answered Jul 16, 2012 at 16:40

Gentle Knight's user avatar

3

If the goal is to be able to display a cell as empty when it in fact has the value zero, then instead of using a formula that results in a blank or empty cell (since there’s no empty() function) instead,

  • where you want a blank cell, return a 0 instead of "" and THEN

  • set the number format for the cells like so, where you will have to come up with what you want for positive and negative numbers (the first two items separated by semi-colons). In my case, the numbers I had were 0, 1, 2… and I wanted 0 to show up empty. (I never did figure out what the text parameter was used for, but it seemed to be required).

    0;0;"";"text"@
    

ib.'s user avatar

ib.

27.4k10 gold badges79 silver badges100 bronze badges

answered Jun 1, 2011 at 6:39

ET-X's user avatar

ET-XET-X

1591 silver badge2 bronze badges

2

This is how I did it for the dataset I was using. It seems convoluted and stupid, but it was the only alternative to learning how to use the VB solution mentioned above.

  1. I did a «copy» of all the data, and pasted the data as «values».
  2. Then I highlighted the pasted data and did a «replace» (CtrlH) the empty cells with some letter, I chose q since it wasn’t anywhere on my data sheet.
  3. Finally, I did another «replace», and replaced q with nothing.

This three step process turned all of the «empty» cells into «blank» cells». I tried merging steps 2 & 3 by simply replacing the blank cell with a blank cell, but that didn’t work—I had to replace the blank cell with some kind of actual text, then replace that text with a blank cell.

ib.'s user avatar

ib.

27.4k10 gold badges79 silver badges100 bronze badges

answered Jan 16, 2011 at 18:28

jeramy's user avatar

jeramyjeramy

1111 silver badge2 bronze badges

2

Use COUNTBLANK(B1)>0 instead of ISBLANK(B1) inside your IF statement.

Unlike ISBLANK(), COUNTBLANK() considers "" as empty and returns 1.

answered Apr 7, 2016 at 9:33

Kevin Vuilleumier's user avatar

1

Try evaluating the cell using LEN. If it contains a formula LEN will return 0. If it contains text it will return greater than 0.

Oleks's user avatar

Oleks

31.8k11 gold badges76 silver badges132 bronze badges

answered Sep 23, 2009 at 16:30

2

Wow, an amazing number of people misread the question. It’s easy to make a cell look empty. The problem is that if you need the cell to be empty, Excel formulas can’t return «no value» but can only return a value. Returning a zero, a space, or even «» is a value.

So you have to return a «magic value» and then replace it with no value using search and replace, or using a VBA script. While you could use a space or «», my advice would be to use an obvious value, such as «NODATE» or «NONUMBER» or «XXXXX» so that you can easily see where it occurs — it’s pretty hard to find «» in a spreadsheet.

answered Jun 24, 2013 at 19:55

Laird Popkin's user avatar

1

So many answers that return a value that LOOKS empty but is not actually an empty as cell as requested…

As requested, if you actually want a formula that returns an empty cell. It IS possible through VBA. So, here is the code to do just exactly that. Start by writing a formula to return the #N/A error wherever you want the cells to be empty. Then my solution automatically clears all the cells which contain that #N/A error. Of course you can modify the code to automatically delete the contents of cells based on anything you like.

Open the «visual basic viewer» (Alt + F11)
Find the workbook of interest in the project explorer and double click it (or right click and select view code). This will open the «view code» window. Select «Workbook» in the (General) dropdown menu and «SheetCalculate» in the (Declarations) dropdown menu.

Paste the following code (based on the answer by J.T. Grimes) inside the Workbook_SheetCalculate function

    For Each cell In Sh.UsedRange.Cells
        If IsError(cell.Value) Then
            If (cell.Value = CVErr(xlErrNA)) Then cell.ClearContents
        End If
    Next

Save your file as a macro enabled workbook

NB: This process is like a scalpel. It will remove the entire contents of any cells that evaluate to the #N/A error so be aware. They will go and you cant get them back without reentering the formula they used to contain.

NB2: Obviously you need to enable macros when you open the file else it won’t work and #N/A errors will remain undeleted

answered Nov 7, 2013 at 22:35

Mr Purple's user avatar

Mr PurpleMr Purple

2,2651 gold badge17 silver badges15 bronze badges

1

What I used was a small hack.
I used T(1), which returned an empty cell.
T is a function in excel that returns its argument if its a string and an empty cell otherwise. So, what you can do is:

=IF(condition,T(1),value)

answered Aug 18, 2019 at 14:55

Ahmed Shahid's user avatar

2

This answer does not fully deal with the OP, but there are have been several times I have had a similar problem and searched for the answer.

If you can recreate the formula or the data if needed (and from your description it looks as if you can), then when you are ready to run the portion that requires the blank cells to be actually empty, then you can select the region and run the following vba macro.

Sub clearBlanks()
    Dim r As Range
    For Each r In Selection.Cells
        If Len(r.Text) = 0 Then
            r.Clear
        End If
    Next r
End Sub

this will wipe out off of the contents of any cell which is currently showing "" or has only a formula

answered Oct 22, 2016 at 19:15

ElderDelp's user avatar

ElderDelpElderDelp

2357 silver badges12 bronze badges

I used the following work around to make my excel looks cleaner:

When you make any calculations the «» will give you error so you want to treat it as a number so I used a nested if statement to return 0 istead of «», and then if the result is 0 this equation will return «»

=IF((IF(A5="",0,A5)+IF(B5="",0,B5)) = 0, "",(IF(A5="",0,A5)+IF(B5="",0,B5)))

This way the excel sheet will look clean…

kleopatra's user avatar

kleopatra

50.8k28 gold badges99 silver badges209 bronze badges

answered Sep 30, 2013 at 7:02

Big Z's user avatar

Big ZBig Z

312 bronze badges

1

If you are using lookup functions like HLOOKUP and VLOOKUP to bring the data into your worksheet place the function inside brackets and the function will return an empty cell instead of a {0}. For Example,

This will return a zero value if lookup cell is empty:

    =HLOOKUP("Lookup Value",Array,ROW,FALSE)

This will return an empty cell if lookup cell is empty:

    =(HLOOKUP("Lookup Value",Array,ROW,FALSE))

I don’t know if this works with other functions…I haven’t tried. I am using Excel 2007 to achieve this.

Edit

To actually get an IF(A1=»», , ) to come back as true there needs to be two lookups in the same cell seperated by an &. The easy way around this is to make the second lookup a cell that is at the end of the row and will always be empty.

Lance Roberts's user avatar

Lance Roberts

22.2k32 gold badges112 silver badges129 bronze badges

answered May 9, 2011 at 6:48

Matthew Dolman's user avatar

Matthew DolmanMatthew Dolman

1,7127 gold badges25 silver badges49 bronze badges

Well so far this is the best I could come up with.

It uses the ISBLANK function to check if the cell is truly empty within an IF statement.
If there is anything in the cell, A1 in this example, even a SPACE character, then the cell is not EMPTY and the calculation will result.
This will keep the calculation errors from showing until you have numbers to work with.

If the cell is EMPTY then the calculation cell will not display the errors from the calculation.If the cell is NOT EMPTY then the calculation results will be displayed.
This will throw an error if your data is bad, the dreaded #DIV/0!

=IF(ISBLANK(A1)," ",STDEV(B5:B14))

Change the cell references and formula as you need to.

shawndreck's user avatar

shawndreck

2,0191 gold badge24 silver badges30 bronze badges

answered Dec 29, 2012 at 19:04

Stevis Geekus's user avatar

1

The answer is positively — you can not use the =IF() function and leave the cell empty. «Looks empty» is not the same as empty. It is a shame two quotation marks back to back do not yield an empty cell without wiping out the formula.

answered Oct 4, 2011 at 15:35

Ken's user avatar

1

I was stripping out single quotes so a telephone number column such as +1-800-123-4567 didn’t result in a computation and yielding a negative number.
I attempted a hack to remove them on empty cells, bar the quote, then hit this issue too (column F). It’s far easier to just call text on the source cell and voila!:

=IF(F2="'","",TEXT(F2,""))

answered Oct 7, 2020 at 5:35

JGFMK's user avatar

JGFMKJGFMK

8,2554 gold badges55 silver badges92 bronze badges

This can be done in Excel, without using the new chart feature of setting #N/A to be a gap. But it’s fiddly. Let’s say that you want to make line on an XY chart. Then:
Row 1: point 1
Row 2: point 2
Row 3: hard empty
Row 4: point 2
Row 5: point 3
Row 6: hard empty
Row 7: point 3
Row 8: point 4
Row 9: hard empty
etc

The result is a lot of separate lines. The formula for the points can control whether omitted by a #N/A. Typically the formulae for the points INDEX() into another range.

answered Apr 10, 2021 at 9:47

jdaw1's user avatar

jdaw1jdaw1

2253 silver badges11 bronze badges

If you are, like me, after an empty cell so that the text in a cell can overflow to an adjacent cell, return "" but set the cell format text direction to be rotated by 5 degrees. If you align left, you will find this causes the text to spill to an adjacent cell as if that cell were empty.

See before and after:
enter image description here

=IF(RANDARRAY(2,10,1,10,TRUE)>8,"abcdefghijklmnopqrstuvwxyz","")

Note the empty cells are not empty but contain "", yet the text can still spill.

enter image description here

answered Jan 26 at 14:24

Greedo's user avatar

GreedoGreedo

4,7992 gold badges29 silver badges76 bronze badges

Google brought me here with a very similar problem, I finally figured out a solution that fits my needs, it might help someone else too…

I used this formula:

=IFERROR(MID(Q2, FIND("{",Q2), FIND("}",Q2) - FIND("{",Q2) + 1), "")

answered Feb 7, 2017 at 22:48

hamish's user avatar

hamishhamish

1,1121 gold badge12 silver badges20 bronze badges

Понравилась статья? Поделить с друзьями:
  • Что такое editor for excel
  • Что такое analysis for microsoft excel
  • Что такое alt код в word
  • Что такое activex для excel
  • Что такое acos в excel