Tramyer
Tramyer

Reputation: 13

How to check if a range contains letter or not

I would like to ask on how to use Isletter on a Range value.

Please see below my code:

If Range("$E$52").Value = **"Isletter"** Then

    Worksheets("Offloading_Tributary").Shapes("Object 115").Visible = False

        Else

    Worksheets("Offloading_Tributary").Shapes("Object 115").Visible = True

End If

Thank you in advance.

Regards,

Upvotes: 0

Views: 3759

Answers (1)

CLR
CLR

Reputation: 12289

To detect if the cell contents contains a letter, you could use:

If Range("$E$52").Value Like "*[a-zA-Z]*" Then
    Worksheets("Offloading_Tributary").Shapes("Object 115").Visible = False
Else
    Worksheets("Offloading_Tributary").Shapes("Object 115").Visible = True
End If

To detect if the cell contents consists only of a single letter:

If Range("$E$52").Value Like "[a-zA-Z]" Then
    Worksheets("Offloading_Tributary").Shapes("Object 115").Visible = False
Else
    Worksheets("Offloading_Tributary").Shapes("Object 115").Visible = True
End If

To detect if the cell contents consists only of a numeric value (and not empty, which it would consider to be zero and therefore numeric):

If IsNumeric(Range("$E$52").Value) And Range("$E$52").Value <> "" Then
    Worksheets("Offloading_Tributary").Shapes("Object 115").Visible = False
Else
    Worksheets("Offloading_Tributary").Shapes("Object 115").Visible = True
End If

Upvotes: 3

Related Questions