Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about searching for a quote in a String

Status
Not open for further replies.

markronz

IS-IT--Management
Mar 20, 2007
93
US
Hello, I am using a form in VBA. I need to make sure that one of the text boxes has more than one quote in it. So " has to appear more than once in the string. Here is a portion of my code.

Code:
If InStr(Sheets("Type1").TextBox1.Value, """) > 1 Then
    MsgBox "String has more than one quote, continue with code"
End If

As you might have guessed, it doesn't like the triple quotes """. I can search for anything else "a", "b", etc and it works fine. So my basic question is, how do I search for a " since it's a key character?

Thanks!
 
Either:
If InStr(Sheets("Type1").TextBox1.Value, """") > 1 Then
Or:
If InStr(Sheets("Type1").TextBox1.Value, Chr(34)) > 1 Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
make sure that one of the text boxes has more than one quote in it
Code:
strVar = Sheets("Type1").TextBox1.Value
intVar = Len(strVar) - Len(Replace(strVar, """", ""))
If intVar <= 1 Then
  MsgBox "'" & strVar & "' has only " & intVar & " quote in it"
End If

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top