Share via

putting quotes in a string

Anonymous
2010-10-29T14:28:00+00:00

i am trying to set a string value with quotes in it.  The problem is that string are naturally surrounded by quotes so there is a problem. 

I want to paste the following string into a cell.  How can I set this value as string:

"RTD("tf.rtdsvr",,"Q",symbol,"LAST")"

thanks

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2010-10-29T15:43:58+00:00

    VB uses quote marks to delineate the beginning and end of strings of text, so if you just put a single quote mark inside, VB can't tell if you mean an internal quote mark or an end/beginning of a new text string... so it issues an error. VB provides a mechanism to allow you to include internal quote marks though... just use two quote marks for each internal one. Example...

    If your quote text is this...   My name is "Rick"

    then double the quote marks....

    My name is ""Rick""

    and then put the surrounding quote marks around it to tell VB is is a text string...

    "My name is ""Rick"""

    This applies to quoted text constants... once the text is in a variable, you do not have to do anything extra afterwards... VB knows what to do with the text contained in a variable once it is in that variable.


    NOTE: Please mark the message or messages (yes, you can mark more than one) that answer your question as the "Answer" so that others will know your question has been resolved.

    Was this answer helpful?

    0 comments No comments
  2. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2010-10-29T15:33:48+00:00

    Am 29.10.2010 16:28, schrieb Cluckers:

    i am trying to set a string value with quotes in it.  The problem is that string are naturally surrounded by quotes so there is a problem.

    It's not, just double the quotes to get a quote in the string.

    Sub Test()

      Dim S As String

      S = "1""2""3"   '1"2"3

      MsgBox S

      S = "RTD(""tf.rtdsvr"",,""Q"",symbol,""LAST"")"

      MsgBox S

    End Sub

    Andreas.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-10-29T14:36:48+00:00

    Use CHR(34) instead of double quotes

    Chr(34) &"RTD("& Chr(34) & "tf.rtdsvr" & Chr(34) &,,& Chr(34) & "Q" & Chr(34) & ",symbol,"& Chr(34) & "LAST" & Chr(34) & ")" & Chr(34)


    gsnu201005

    Was this answer helpful?

    0 comments No comments