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
=IF(C5<>"","Yes","No")
=IF(C9<>"",$C$5,$C$6)
|
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)). |
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)). |
Dim ws As Worksheet
If ws.Range("C5") <> "" Then
Else
End If
End Sub
Dim ws As Worksheet
If ws.Range("C9") <> "" Then
Else
End If
End Sub
Dim ws As Worksheet
For x = 5 To 11
If ws.Cells(x, 3) <> "" Then
Else
Next x
End Sub
Dim ws As Worksheet
For x = 9 To 15
If ws.Cells(x, 3) <> "" Then
Else
Next x
End Sub
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.
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.
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.
Note 1: If the cell that is being tested is returning a value of ("") this VBA code will identify the cell as blank.
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.
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.
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.
Note 1: If the cell that is being tested is returning a value of ("") this VBA code will identify the cell as blank.
Dim ws As Worksheet
If Not (IsEmpty(ws.Range("C5")))Then
Else
End If
End Sub
Dim ws As Worksheet
If Not (IsEmpty(ws.Range("C9")))Then
Else
End If
End Sub
Dim ws As Worksheet
For x = 5 To 11
If Not (IsEmpty(ws.Cells(x, 3))) Then
Else
Next x
End Sub
Dim ws As Worksheet
For x = 9 To 15
If Not (IsEmpty(ws.Cells(x, 3))) Then
Else
Next x
End Sub
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.
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.
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.
Note 1: If the cell that is being tested is returning a value of ("") this VBA code will identify the cell as not blank.
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.
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.
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.
Note 1: If the cell that is being tested is returning a value of ("") this VBA code will identify the cell as blank.
Dim ws As Worksheet
If ws.Range("C5") <> vbNullString Then
Else
End If
End Sub
Dim ws As Worksheet
If ws.Range("C9") <> vbNullString Then
Else
End If
End Sub
Dim ws As Worksheet
For x = 5 To 11
If ws.Cells(x, 3) <> vbNullString Then
Else
Next x
End Sub
Dim ws As Worksheet
For x = 9 To 15
If ws.Cells(x, 3) <> vbNullString Then
Else
Next x
End Sub
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.
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.
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.
Note 1: If the cell that is being tested is returning a value of ("") this VBA code will identify the cell as blank.
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.
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.
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.
Note 1: If the cell that is being tested is returning a value of ("") this VBA code will identify the cell as blank.
Related Topic | Description | Related Topic and Description |
---|---|---|
If a cell is blank | How to test if a cell is blank and return a specified value using Excel and VBA methods | |
If a cell is blank in a range | How to test if a cell is blank in a range and return a value using Excel and VBA methods | |
If a cell is not blank in a range | How to test if a cell is not blank in a range and return a value using Excel and VBA methods | |
Count cells that are blank | How to count cells that are blank using Excel and VBA methods | |
Count cells that are not blank | How to count cells that are not blank using Excel and VBA methods |
Related Functions | Description | Related Functions and Description |
---|---|---|
IF Function | 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 | |
ISBLANK Function | The Excel ISBLANK function is used to check if a cell is empty | |
NOT Function | The Excel NOT function returns the opposite result of a logical value |