简体   繁体   中英

Find pattern in a string variable with Excel Vba

I have a string v = "word 1, word 2, word 3, ..., word n"

And I want to check if we find the word 2. If yes display "word 2 exists"

I tried to use the function Find but I think she need a Range however I just have a variable.

Thank you for your help !

Use instr()

Sub isItInThere()
    v = "word 1, word 2, word 3, ..., word n"
    If InStr(v, "word 2") > 0 Then MsgBox "word 2 exists"
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM