Consulting

Results 1 to 5 of 5

Thread: What is escape character for quotation marks?

  1. #1

    What is escape character for quotation marks?

    A VBA newbie question...

    What is the escape character for Excel VBA? I want to do print a string that contains quotation marks to a cell. In other worrds the "" marks are *within* the string quotation marks...

    This code will not work:

    Sheets("sheet1").Cells(1,1).value = "He said, "this is Excel" "

    ...what should it be?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    You double up on the quotes

    Sheets("sheet1").Cells(1,1).value = "He said, ""this is Excel"" "
    Last edited by Aussiebear; 04-13-2023 at 12:56 PM. Reason: Adjusted the code tags
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3

    Thanks very much...

    Yep, that works! Thanks very much...

  4. #4
    VBAX Expert
    Joined
    Dec 2007
    Posts
    522
    Location
    I know that xld has provided a great solution for this.

    But as a fellow newb, knowing how many " to put in confuses me in the VB Editor, and thought I might add something that may be easier to read.

    You can use Chr(34) Whhich is VBA code for and inverted comma to be used inside a string, not to mark the start and end of a string.

    So your example, would look like the following:

    Sheets("sheet1").Cells(1,1).value = "He said, "& Chr(34) &" this is Excel" & Chr(34)
    Hope this offers you an alternative going forward, but xld's solution works a treat.

  5. #5

    thank-you!

    Yes, that's good advice as well - thank-you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •