Aleksei Nikolaevich
Aleksei Nikolaevich

Reputation: 325

How to find if a cell contains a substring Excel

I have the following VBA function

Function .....
..........
If (IsNumeric(x) And ((x = "*9999999*") = False)) Then
.......
Else
...........
End If
End Function

I need to know if a string contains a substring "9999999". How can I do this?

Upvotes: 0

Views: 2424

Answers (2)

Santosh
Santosh

Reputation: 12353

You may use the Like Operator.

Sub test()

Dim str1 As String
Dim str2 As String

str1 = "dhfjd9999999dfda"
str2 = "ddsss999dfdfsfd"


MsgBox str1 Like "*9999999*"
MsgBox str2 Like "*9999999*"

End Sub

Upvotes: 1

mattboy
mattboy

Reputation: 2910

If Instr(x, "9999999") > 0 Then ... should do it.

Upvotes: 1

Related Questions