PDA

View Full Version : [SOLVED] What is escape character for quotation marks?



paul_0722
07-19-2008, 03:52 AM
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?

Bob Phillips
07-19-2008, 03:53 AM
You double up on the quotes


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

paul_0722
07-19-2008, 04:08 AM
Yep, that works! Thanks very much...

xluser2007
07-19-2008, 04:24 AM
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.

paul_0722
07-20-2008, 01:32 PM
Yes, that's good advice as well - thank-you!