If a range contains text

This tutorial shows how to test if a range contains at least one cell with only text by using an Excel formula or VBA

Example: If a range contains text

If a range contains text

METHOD 1. If a range contains text

EXCEL

=IF(COUNTIF(B5:B9,"*")>0,"Contains Text","No Text")
This formula uses a combination of the Excel IF and COUNTIF functions to test if a selected range (B5:B9) contains a cell that only captures text. The COUNTIF function, with a criteria of "*", counts the number of cells in a range that contain only text, and then the IF function is used to return a value of "Contains Text" if the count of cells that contain text is greater than 0, alternatively, if there are no cells in a range that contain text the IF function will return a value of "No Text".

METHOD 1. If a range contains text

VBA

Sub If_Range_Contains_Text()
'declare variables
Dim ws As Worksheet
Dim Rng As Range
Dim cell As Range
Set ws = Worksheets("Analysis")
Set Rng = ws.Range("B5:B9")
'calculate if a range contains text
For Each cell In Rng

If Application.WorksheetFunction.IsText(cell) = True Then

ws.Range("E4") = "Contains Text"
Exit For

Else

ws.Range("E4") = "No Text"

End If

Next cell

End Sub

ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("E4") in the VBA code.
Range to Test: Select the range that you want to search through for cells that contain only text by changing the range reference ("B5:B9") in the VBA code.
True and False Results: In this example if a range contains at least one cell that only has text the VBA code will return a value of "Contains Text". If a range does not contain any cells that only has text the VBA code will return a value of "No Text". Both of these values can be changed to whatever value you desire by directly changing them in the VBA code.
Worksheet Selection: Select the worksheet which captures the range that you want to test for cells that contain only text 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.
ADDITIONAL NOTES
Note 1: 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.

Explanation about how to test if a range contains text

EXPLANATION

EXPLANATION

This tutorial shows how to test if a range contains a cell with text and return a specified value if the formula tests true or false, by using an Excel formula and VBA.
This tutorial provides one Excel method that can be applied to test if a range contains at least one cell that has only text by using a combination of Excel IF and COUNTIFfunctions. In this example, if the COUNTIF function, with the criteria of "*", returns a value of greater than 0, meaning the range contains cells that only captures text, the test is TRUE and the formula will return a "Contains Text" value. Alternatively, if the COUNTIF function returns a value of 0, meaning the range does not have any cells that only capture text, the test is FALSE and the formula will return a "No Text" value.
This tutorial provides one VBA method that can be applied to test if a range contains at least one cell that has only text by looping through each cell in a selected range and using the IsText function to identify if a cell contains only text. As soon as the it identifies the first cell that contains only text it will return a value of "Contains Text" and exit loop. If the range does not contain any cells that contain only text, after looping through each cell in a range, it will return a value "No Text".
FORMULA
=IF(COUNTIF(range,"*")>0,value_if_true, value_if_false)
ARGUMENTS
range: The range of cells you want to test if they contain only text.
value_if_true: Value to be returned if the range contains at least one cell that has only text.
value_if_false: Value to be returned if the range does not contain any cells that contain only text.

RELATED TOPICS

Related Topic Description Related Topic and Description
How to test if at least one cell in a range contains a number and return a specified value using Excel and VBA
How to test if a range contains a specific value by column and return a specified value using Excel and VBA methods
How to test if a range contains a value less than a specific value and return a specified value using Excel and VBA methods
How to test if a range contains a specific value by row and return a specified value using Excel and VBA methods
How test if a cell contains text and return a specified value using Excel and VBA

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 COUNTIF function returns the number of cells in a range that meet a specified criteria