How can I use IsText to check if a cell is text in VBA?

IsText is a function in Visual Basic for Applications (VBA) that allows users to check whether a cell contains text or not. This function takes a cell reference as an input and returns a Boolean value (True or False) based on whether the cell contains text or not. By using IsText, users can easily determine the type of data stored in a cell and perform specific operations based on the result. This function is particularly useful in data analysis and manipulation tasks where identifying text values is crucial. With IsText, VBA users can efficiently and accurately identify and handle text data within their code.

VBA: Use IsText to Check if Cell is Text


You can use the IsText method in VBA to check if a given cell is text.

This function will return True if the value in a given cell is recognized as text.

Otherwise, the function will return False.

Here is one common way to use this function in practice:

Sub CheckText()
    
    Dim i As Integer

    For i = 1 To 9
    
        If IsText(Range("A" & i)) = True Then
            Range("B" & i) = "Cell is Text"
        Else
            Range("B" & i) = "Cell is Not Text"
        End IfNext i
    
End Sub

This particular macro will check if each cell in the range A1:A9 is text.

If a cell is text, then “Cell is Text” will be returned in the corresponding cell in the range B1:B9.

If a cell is not text, then “Cell is Not Text” will be returned instead.

The following example shows how to use this syntax in practice.

Example: How to Use IsText in VBA

Suppose we have the following column of values in Excel:

Suppose we would like to check if each cell in column A is text.

We can create the following macro to do so:

Sub CheckText()
    
    Dim i As Integer

    For i = 1 To 9
    
        If IsText(Range("A" & i)) = True Then
            Range("B" & i) = "Cell is Text"
        Else
            Range("B" & i) = "Cell is Not Text"
        End IfNext i
    
End Sub

When we run this macro, we receive the following output:

Note that cells with both text and numbers are recognized as text.

In order for a cell to be recognized as a number, it must only contain numbers.

Note: You can find the complete documentation for the VBA IsText function .

Additional Resources

The following tutorials explain how to perform other common tasks in VBA:

x