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.
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».
=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?
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:
=IF(A1="",TRUE) // IF A1 is blank
=IF(A1<>"",TRUE) // IF A1 is not blank
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<>"","Done","")
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:
=IF(D5<>"","Done","Not done")
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:
=IF(ISBLANK(D5),"","Done")
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:
=IF(NOT(ISBLANK(D5)),"Done","")
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:
=IF(LEN(A1)>0,TRUE)
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.
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!
17 авг. 2022 г.
читать 2 мин
Вы можете использовать следующую формулу в Excel для выполнения какой-либо задачи, если ячейка не пуста:
=IF( A1 <> "" , Value_If_Not_Empty, Value_If_Empty)
Эта конкретная формула проверяет, пуста ли ячейка A1 .
Если он не пустой, то возвращается Value_If_Not_Empty .
Если он пуст, возвращается значение Value_If_Empty .
В следующем примере показано, как использовать эту формулу на практике.
Пример: используйте формулу «Если не пусто» в Excel
Предположим, у нас есть следующий набор данных в Excel, который содержит информацию о различных баскетбольных командах:
Мы можем использовать следующую формулу, чтобы вернуть значение «Команда существует», если ячейка в столбце A не пуста.
В противном случае мы вернем значение «Не существует»:
=IF( A2 <> "" , "Team Exists", "Does Not Exist")
На следующем снимке экрана показано, как использовать эту формулу на практике:
Если имя команды не пусто в столбце А, возвращается «Команда существует».
В противном случае возвращается «Не существует».
Если бы мы хотели, мы могли бы также возвращать числовые значения вместо символьных значений.
Например, мы могли бы использовать следующую формулу, чтобы вернуть значение столбца очков, разделенное на два, если ячейка в столбце A не пуста.
В противном случае мы вернем пустое значение:
=IF( A2 <> "" , B2 / 2 , "" )
На следующем снимке экрана показано, как использовать эту формулу на практике:
Если название команды не пусто в столбце A, то мы возвращаем значение в столбце очков, умноженное на два.
В противном случае мы возвращаем пустое значение.
Дополнительные ресурсы
В следующих руководствах объясняется, как выполнять другие распространенные задачи в Google Таблицах:
Как отфильтровать ячейки, содержащие текст, в Google Sheets
Как извлечь подстроку в Google Sheets
Как извлечь числа из строки в Google Sheets
EXCEL FORMULA 1. If a cell is not blank using the IF function
EXCEL
Hard coded formula
Cell reference formula
GENERIC FORMULA =IF(cell_ref<>»», value_if_true, value_if_false) ARGUMENTS GENERIC FORMULA =IF(cell_ref<>»», value_if_true, value_if_false) ARGUMENTS EXPLANATION This formula uses the IF function with a test criteria of two double quotation marks («»), without any value inserted between them and ‘does not equal to’ sign (<>) in front of them, to assess if a cell is not empty and return a specific value. The expression <>»» means «not empty». If a cell is not blank the formula will return a value that has been assigned as the true value, alternatively if a cell is blank the formula will return a value assigned as the false value. With this formula you can enter the values, that will be returned if the cell is empty or not, directly into the formula or reference them to specific cells that capture these values. Click on either the Hard Coded or Cell Reference button to view the formula that has the return values directly entered into the formula or referenced to specific cells that capture these values, respectively. In this example the formula tests if a specific cell is not blank. If the cell is not blank the formula will return a value of «Yes» (hard coded example) or value in cell C5 (cell reference example). If the cell is empty the formula will return a value of «No» (hard coded example) or value in cell C6 (cell reference example). If you are using the formula with values entered directly in the formula and want to return a numerical value, instead of a text value, you do not need to apply the double quotation marks around the values that are to be returned e.g. (=IF(C5<>»»,1,0)). |
EXCEL FORMULA 2. If a cell is not blank using the IF, NOT and ISBLANK functions
EXCEL
Hard coded formula
Cell reference formula
GENERIC FORMULA =IF(NOT(ISBLANK(cell_ref)), value_if_true, value_if_false) ARGUMENTS GENERIC FORMULA =IF(NOT(ISBLANK(cell_ref)), value_if_true, value_if_false) ARGUMENTS EXPLANATION This formula uses a combination of the IF, NOT and ISBLANK functions to assess if a cell is not blank and return a specific value. Unlike the first formula, which uses the double quotation marks («») to test if the selected cell is not blank, this formula uses the NOT and ISBLANK functions. If the cell is not blank the ISBLANK function will return FALSE, alternatively it will return TRUE. The NOT function will then return the opposite to what the ISBLANK function has returned. Therefore, if the cell is not blank the combination of the NOT and ISBLANK function will return a TRUE value. The formula will then return a value that has been assigned as the true value, alternatively if the cell is blank the formula will return a value assigned as the false value. With this formula you can enter the values, that will be returned if the cell is empty or not, directly into the formula or reference them to specific cells that capture these values. Click on either the Hard Coded or Cell Reference button to view the formula that has the return values directly entered into the formula or referenced to specific cells that capture these values, respectively. In this example the formula tests if a specific cell is not blank. If the cell is not blank the formula will return a value of «Yes» (hard coded example) or value in cell C5 (cell reference example). If the cell is empty the formula will return a value of «No» (hard coded example) or value in cell C6 (cell reference example). If you are using the formula with values entered directly in the formula and want to return a numerical value, instead of a text value, you do not need to apply the double quotation marks around the values that are to be returned e.g. (=IF(NOT(ISBLANK(C5)),1,0)). |
VBA CODE 1. If a cell is not blank using the If Statement
VBA
Hard coded against single cell
Sub If_a_cell_is_not_blank()
Dim ws As Worksheet
Set ws = Worksheets(«Analysis»)
If ws.Range(«C5») <> «» Then
ws.Range(«D5») = «Yes»
Else
ws.Range(«D5») = «No»
End If
End Sub
Cell reference against single cell
Sub If_a_cell_is_not_blank()
Dim ws As Worksheet
Set ws = Worksheets(«Analysis»)
If ws.Range(«C9») <> «» Then
ws.Range(«D9») = ws.Range(«C5»)
Else
ws.Range(«D9») = ws.Range(«C6»)
End If
End Sub
Hard coded against range of cells
Sub If_a_cell_is_not_blank()
Dim ws As Worksheet
Set ws = Worksheets(«Analysis»)
For x = 5 To 11
If ws.Cells(x, 3) <> «» Then
ws.Cells(x, 4) = «Yes»
Else
ws.Cells(x, 4) = «No»
End If
Next x
End Sub
Cell reference against range of cells
Sub If_a_cell_is_not_blank()
Dim ws As Worksheet
Set ws = Worksheets(«Analysis»)
For x = 9 To 15
If ws.Cells(x, 3) <> «» Then
ws.Cells(x, 4) = ws.Range(«C5»)
Else
ws.Cells(x, 4) = ws.Range(«C6»)
End If
Next x
End Sub
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 not 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 not 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 not blank the VBA code will return a value of «Yes». If a cell is blank the VBA code will return a value of «No». 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 not 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 not 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 not blank the VBA code will return a value stored in cell C5. If a cell is 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 Range: 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 not 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 not blank the VBA code will return a value of «Yes». If a cell is blank the VBA code will return a value of «No». 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 Range: 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 not 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 not blank the VBA code will return a value stored in cell C5. If a cell is 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.
VBA CODE 2. If a cell is not blank using Not and IsEmpty
VBA
Hard coded against single cell
Sub If_a_cell_is_not_blank_using_Not_and_IsEmpty()
Dim ws As Worksheet
Set ws = Worksheets(«Analysis»)
If Not (IsEmpty(ws.Range(«C5»)))Then
ws.Range(«D5») = «Yes»
Else
ws.Range(«D5») = «No»
End If
End Sub
Cell reference against single cell
Sub If_a_cell_is_not_blank_using_Not_and_IsEmpty()
Dim ws As Worksheet
Set ws = Worksheets(«Analysis»)
If Not (IsEmpty(ws.Range(«C9»)))Then
ws.Range(«D9») = ws.Range(«C5»)
Else
ws.Range(«D9») = ws.Range(«C6»)
End If
End Sub
Hard coded against range of cells
Sub If_a_cell_is_not_blank_using_Not_and_IsEmpty()
Dim ws As Worksheet
Set ws = Worksheets(«Analysis»)
For x = 5 To 11
If Not (IsEmpty(ws.Cells(x, 3))) Then
ws.Cells(x, 4) = «Yes»
Else
ws.Cells(x, 4) = «No»
End If
Next x
End Sub
Cell reference against range of cells
Sub If_a_cell_is_not_blank_using_Not_and_IsEmpty()
Dim ws As Worksheet
Set ws = Worksheets(«Analysis»)
For x = 9 To 15
If Not (IsEmpty(ws.Cells(x, 3))) Then
ws.Cells(x, 4) = ws.Range(«C5»)
Else
ws.Cells(x, 4) = ws.Range(«C6»)
End If
Next x
End Sub
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 not 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 not 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 not blank the VBA code will return a value of «Yes». If a cell is blank the VBA code will return a value of «No». 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 not 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 not 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 not 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 not blank the VBA code will return a value stored in cell C5. If a cell is 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 not blank.
KEY PARAMETERS
Output and Test Range: 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 not 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 not blank the VBA code will return a value of «Yes». If a cell is blank the VBA code will return a value of «No». 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 Range: 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 not 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 not blank the VBA code will return a value stored in cell C5. If a cell is 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.
VBA CODE 3. If a cell is not blank using vbNullString
VBA
Hard coded against single cell
Sub If_a_cell_is_not_blank_using_vbNullString()
Dim ws As Worksheet
Set ws = Worksheets(«Analysis»)
If ws.Range(«C5») <> vbNullString Then
ws.Range(«D5») = «Yes»
Else
ws.Range(«D5») = «No»
End If
End Sub
Cell reference against single cell
Sub If_a_cell_is_not_blank_using_vbNullString()
Dim ws As Worksheet
Set ws = Worksheets(«Analysis»)
If ws.Range(«C9») <> vbNullString Then
ws.Range(«D9») = ws.Range(«C5»)
Else
ws.Range(«D9») = ws.Range(«C6»)
End If
End Sub
Hard coded against range of cells
Sub If_a_cell_is_not_blank_using_vbNullString()
Dim ws As Worksheet
Set ws = Worksheets(«Analysis»)
For x = 5 To 11
If ws.Cells(x, 3) <> vbNullString Then
ws.Cells(x, 4) = «Yes»
Else
ws.Cells(x, 4) = «No»
End If
Next x
End Sub
Cell reference against range of cells
Sub If_a_cell_is_not_blank_using_vbNullString()
Dim ws As Worksheet
Set ws = Worksheets(«Analysis»)
For x = 9 To 15
If ws.Cells(x, 3) <> vbNullString Then
ws.Cells(x, 4) = ws.Range(«C5»)
Else
ws.Cells(x, 4) = ws.Range(«C6»)
End If
Next x
End Sub
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 not 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 not 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 not blank the VBA code will return a value of «Yes». If a cell is blank the VBA code will return a value of «No». 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 not 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 not 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 not blank the VBA code will return a value stored in cell C5. If a cell is 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 not 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 not blank the VBA code will return a value of «Yes». If a cell is blank the VBA code will return a value of «No». 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 not 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 not blank the VBA code will return a value stored in cell C5. If a cell is 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.
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)
- First, in cell B1, enter IF in the cell.
- Now, in the first argument, enter the ISBLANK and refer to cell A1 and enter the closing parentheses.
- Next, in the second argument, use the “Blank” value.
- After that, in the third argument, use “Non-Blank”.
- 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.
You can use the following formula in Excel to perform some task if a cell is not empty:
=IF(A1<>"", Value_If_Not_Empty, Value_If_Empty)
This particular formula checks if cell A1 is empty.
If it is not empty, then Value_If_Not_Empty is returned.
If it is empty, then Value_If_Empty is returned.
The following example shows how to use this formula in practice.
Example: Use “If Not Empty” Formula in Excel
Suppose we have the following dataset in Excel that contains information about various basketball teams:
We can use the following formula to return a value of “Team Exists” if the cell in column A is not empty.
Otherwise, we’ll return a value of “Does Not Exist”:
=IF(A2<>"", "Team Exists", "Does Not Exist")
The following screenshot shows how to use this formula in practice:
If the team name is not empty in column A, then “Team Exists” is returned.
Otherwise, “Does Not Exist” is returned.
If we’d like, we could also return numeric values instead of character values.
For example, we could use the following formula to return the value of the points column divided by two if the cell in column A is not empty.
Otherwise, we’ll return an empty value:
=IF(A2<>"", B2/2, "")
The following screenshot shows how to use this formula in practice:
If the team name is not empty in column A, then we return the value in the points column multiplied by two.
Otherwise, we return an empty value.
Additional Resources
The following tutorials explain how to perform other common tasks in Excel:
How to Replace Blank Cells with Zero in Excel
How to Replace #N/A Values in Excel
How to Ignore #VALUE! Error in Excel
We can determine if a cell is not blank in Excel by either using the IF function or by using the IF and ISBLANK function combined. This tutorial will assist all levels of Excel users in both methods to identify non-blank cells
Figure 1. Final result: Determine if a cell is not blank in Excel
IF Function in Excel
IF function evaluates a given logical test and returns a TRUE or a FALSE
Syntax
=IF(logical_test, [value_if_true], [value_if_false])
- The arguments “value_if_true” and “value_if_false” are optional. If left blank, the function will return TRUE if the logical test is met, and FALSE if otherwise.
ISBLANK Function in Excel
ISBLANK function is more straightforward. It tests whether a value or a cell is blank or not.
Syntax
=ISBLANK(value)
- The function returns TRUE if the value is blank; FALSE if otherwise
Setting up the Data
Below is a list of Projects and a column for Date Completed. We want to know if column C for the “Date Completed” is blank or not.
Figure 2. Sample data to determine if a cell is not blank
Determine If a Cell is Not Blank
Using the IF function
In cell D3, enter the formula:
=IF(C3<>"","Not blank","Blank")
- The symbol <> in Excel means “not equal to”
- “” in Excel means empty string, or blank
- C3<>”” means C3 is not equal to blank, or C3 is not blank
This formula returns “Not blank” because cell C3 is not blank. It has the value “July 26, 2018”.
Figure 3. Entering the IF formula to determine if a cell is not blank
In cell D4, enter the formula:
=IF(C4<>"","Not blank","Blank")
The result is “Blank” because cell D4 is empty.
Figure 4. Output: Using IF to determine if a cell is not blank
Using the IF and ISBLANK function
In cell D5, enter the formula:
=IF(ISBLANK(C5),"Blank","Not Blank")
- ISBLANK evaluates whether cell C5 is blank or not
- If the ISBLANK function returns TRUE, the formula will return “Blank”; otherwise, it returns “Not Blank”
- The result is “Blank” because C5 is empty
Figure 5. Final result: Using IF and ISBLANK to determine if a cell is not blank
Note
We can customize the action that the IF function will return depending on the logical test results.
Example
We want to return the status “Completed” if the cell in column C is not blank, and “In Progress” if otherwise.
Enter the following formula:
In cell D3: =IF(C3<>"","Completed","In Progress")
In cell D4: =IF(C4<>"","Completed","In Progress")
In cell D5: =IF(ISBLANK(C5),"In Progress","Completed")
In cell D6: =IF(ISBLANK(C6),"In Progress","Completed")
Figure 6. Final result: Using IF and ISBLANK to determine the status of a project
Most of the time, the problem you will need to solve will be more complex than a simple application of a formula or function. If you want to save hours of research and frustration, try our live Excelchat service! Our Excel Experts are available 24/7 to answer any Excel question you may have. We guarantee a connection within 30 seconds and a customized solution within 20 minutes.
Are you still looking for help with the IF function? View our comprehensive round-up of IF function tutorials here.
There are many ways to force excel for calculating a formula only if given cell/s are not blank. In this article, we will explore all the methods of calculating only «if not blank» condition.
So to demonstrate all the cases, I have prepared below data
In row 4, I want the difference of months of years 2109 and 2018. For that, I will subtract 2018’s month’s data from 2019’s month’s data. The condition is, if either cell is blank, there should be no calculation. Let’s explore in how many ways you can force excel, if cell is not blank.
Calculate If Not Blank using IF function with OR Function.
The first function we think of is IF function, when it comes to conditional output. In this example, we will use IF and OR function together.
So if you want to calculate if all cells are non blank then use below formula.
Write this formula in cell B4 and fill right (CTRL+R).
=IF(OR(B3=»»,B2=»»),»»,B2-B3)
How Does It work?
The OR function checks if B3 and B2 are blank or not. If either of the cell is blank, it returns TRUE. Now, for True, IF is printing “” (nothing/blank) and for False, it is printing the calculation.
The same thing can be done using IF with AND function, we just need to switch places of True Output and False Output.
=IF(AND(B3<>»»,B2<>»»),B2-B3,»»)
In this case, if any of the cells is blank, AND function returns false. And then you know how IF treats the false output.
Using the ISBLANK function
In the above formula, we are using cell=”” to check if the cell is blank or not. Well, the same thing can be done using the ISBLANK function.
=IF(OR(ISBLANK(B3),ISBLANK(B2)),””,B2-B3)
It does the same “if not blank then calculate” thing as above. It’s just uses a formula to check if cell is blank or not.
Calculate If Cell is Not Blank Using COUNTBLANK
In above example, we had only two cells to check. But what if we want a long-range to sum, and if the range has any blank cell, it should not perform calculation. In this case we can use COUNTBLANK function.
=IF(COUNTBLANK(B2:H2),»»,SUM(B2:H2))
Here, count blank returns the count blank cells in range(B2:H2). In excel, any value grater then 0 is treated as TRUE. So, if ISBLANK function finds a any blank cell, it returns a positive value. IF gets its check value as TRUE. According to the above formula, if prints nothing, if there is at least one blank cell in the range. Otherwise, the SUM function is executed.
Using the COUNTA function
If you know, how many nonblank cells there should be to perform an operation, then COUNTA function can also be used.
For example, in range B2:H2, I want to do SUM if none of the cells are blank.
So there is 7 cell in B2:H2. To do calculation only if no cells are blank, I will write below formula.
=IF(COUNTA(B3:H3)=7,SUM(B3:H3),»»)
As we know, COUNTA function returns a number of nonblank cells in the given range. Here we check the non-blank cell are 7. If they are no blank cells, the calculation takes place otherwise not.
This function works with all kinds of values. But if you want to do operation only if the cells have numeric values only, then use COUNT Function instead.
So, as you can see that there are many ways to achieve this. There’s never only one path. Choose the path that fits for you. If you have any queries regarding this article, feel free to ask in the comments section below.
Related Articles:
How to Calculate Only If Cell is Not Blank in Excel
Adjusting a Formula to Return a Blank
Checking Whether Cells in a Range are Blank, and Counting the Blank Cells
SUMIF with non-blank cells
Only Return Results from Non-Blank Cells
Popular Articles
50 Excel Shortcut to Increase Your Productivity : Get faster at your task. These 50 shortcuts will make you work even faster on Excel.
How to use the VLOOKUP Function in Excel : This is one of the most used and popular functions of excel that is used to lookup value from different ranges and sheets.
How to use the COUNTIF function in Excel : Count values with conditions using this amazing function. You don’t need to filter your data to count specific values. Countif function is essential to prepare your dashboard.
How to use the SUMIF Function in Excel : This is another dashboard essential function. This helps you sum up values on specific conditions.