Search 3 "in a string using InStr () vba

I am trying to find a string that includes a quote with double text ". ex. find line 3 "in the larger line 43-9120-BT-1207-3"-150H21-NI. Currently this is what I have.

Dim line As String
line = "43-9120-BT-1207-3"-150H21-NI"

If InStr(1, line, Str$(34) & 3" & Str$(34)) > 0 Then
.
.
.
end if

I can never enter the if statement, I tried many combinations of Str $ (34) s and several "s, but I get an error

Expected: List Operator

Can anyone explain how to look for a double quote string at the end of it?

+4
source share
2 answers

This will find 3"in your line line:

'assuming:
'activecell = 43-9120-BT-1207-3"-150H21-NI
'next:
line = activecell
'search for 3"
If InStr(1, line, "3" & Chr(34)) > 0 Then MsgBox "OK"
+3
source

If the string is hard-coded, you need to avoid it by double double quotes:

line = "43-9120-BT-1207-3""-150H21-NI"

", ', .

: .

If InStr(1, line, "3""" ) > 0 Then

0

Source: https://habr.com/ru/post/1529222/


All Articles