CONTAINS SPECIFIC TEXT OR NUMBER

  • Thread starter Thread starter D.S.
  • Start date Start date
D

D.S.

Is there a way to test a cell for a specific text or number? Lets say a cell
contents of cell A1 begins with the word <Check>, how would I test for that?
 
One way:

Dim bCheck As Boolean
bCheck = Range("A1").Text Like "Check*"

another:

Dim bCheck As Boolean
bCheck = Left(Range("A1").Text, 5) = "Check"

note these are case sensitive. To make them case insensitive, you can do
something like:

Dim bCheck As Boolean
bCheck = UCase(Range("A1").Text) Like "CHECK*"
 
Thank you, I knew about the 'Left' function, I knew there was another and
couldn't remember what it was. Kept thinking it was some like 'contains'.

'Like' should work splendidly. Thanks again


JE McGimpsey said:
One way:

Dim bCheck As Boolean
bCheck = Range("A1").Text Like "Check*"

another:

Dim bCheck As Boolean
bCheck = Left(Range("A1").Text, 5) = "Check"

note these are case sensitive. To make them case insensitive, you can do
something like:

Dim bCheck As Boolean
bCheck = UCase(Range("A1").Text) Like "CHECK*"
that?
 
Back
Top