If a cell is not blank

This tutorial shows how to test if a cell is not blank and return a value if the test is True or False through the use of Excel formulas, with the IF, NOT and ISBLANK functions, or VBA

EXCEL FORMULA 1. If a cell is not blank using the IF function

EXCEL

Hard coded formula
If a cell is not blank
Cell reference formula
If a cell is not blank
=IF(C5<>"","Yes","No")
=IF(C9<>"",$C$5,$C$6)
GENERIC FORMULA

=IF(cell_ref<>"", value_if_true, value_if_false)

ARGUMENTS
cell_ref: A cell that you want to check if it's not blank.
value_if_true: Return a value if the cell that is being tested is not blank.
value_if_false: Return a value if the cell that is being tested is blank.

GENERIC FORMULA

=IF(cell_ref<>"", value_if_true, value_if_false)

ARGUMENTS
cell_ref: A cell that you want to check if it's not blank.
value_if_true: Return a value if the cell that is being tested is not blank.
value_if_false: Return a value if the cell that is being tested is blank.

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
If a cell is not blank
Cell reference formula
If a cell is not blank
=IF(NOT(ISBLANK(C5)),"Yes","No")
=IF(NOT(ISBLANK(C9)),$C$5,$C$6)
GENERIC FORMULA

=IF(NOT(ISBLANK(cell_ref)), value_if_true, value_if_false)

ARGUMENTS
cell_ref: A cell that you want to check if it's blank.
value_if_true: Value to be returned if the cell that is being tested is blank.
value_if_false: Value to be returned if the cell that is being tested is not blank.

GENERIC FORMULA

=IF(NOT(ISBLANK(cell_ref)), value_if_true, value_if_false)

ARGUMENTS
cell_ref: A cell that you want to check if it's blank.
value_if_true: Value to be returned if the cell that is being tested is blank.
value_if_false: Value to be returned if the cell that is being tested is not blank.

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()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'calculate if a cell is not blank
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()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'calculate if a cell is not blank
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()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'calculate if a cell is not blank across a range of cells with a For Loop
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()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'calculate if a cell is not blank across a range of cells with a For Loop
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()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'calculate if a cell is not blank
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()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'calculate if a cell is not blank
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()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'calculate if a cell is not blank across a range of cells with a For Loop
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()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'calculate if a cell is not blank across a range of cells with a For Loop
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()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'calculate if a cell is not blank
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()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'calculate if a cell is not blank
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()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'calculate if a cell is not blank across a range of cells with a For Loop
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()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'calculate if a cell is not blank across a range of cells with a For Loop
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.

RELATED TOPICS

Related Topic Description Related Topic and Description
How to test if a cell is blank and return a specified value using Excel and VBA methods
How to test if a cell is blank in a range and return a value using Excel and VBA methods
How to test if a cell is not blank in a range and return a value using Excel and VBA methods
How to count cells that are blank using Excel and VBA methods
How to count cells that are not blank using Excel and VBA methods

RELATED FUNCTIONS

Related Functions Description Related Functions and Description
The Excel IF function performs a test on specified conditions entered into the formula and returns a specified value if the result is TRUE or another specified value if the result is FALSE
The Excel ISBLANK function is used to check if a cell is empty
The Excel NOT function returns the opposite result of a logical value