0

Is it possible to add the " character as text in VBA? This character, I assume, is used to specify text in VBA, so when I try and add the following code, I receive errors:

Sheets("SalesDataSheet").Range("C5") = "=TEXT(B5,"mmm yyy")"

Alternatively, is there VB code which can execute the function I am trying to paste to the cell?

Thanks in advance.

Nicholas
  • 11
  • 5
  • Exact duplicate of [Expected End of Statement in formula with quotes](http://stackoverflow.com/questions/24173238/vba-compile-error-expectedend-of-statement) – Jean-François Corbett Mar 06 '15 at 08:49

3 Answers3

0

You have to double the quote to escape it:

Sheets("SalesDataSheet").Range("C5") = "=TEXT(B5,""mmm yyy"")"
paulroho
  • 1,234
  • 1
  • 11
  • 27
0

I also found this as a working alternative to pasting the code into the cell:

Sheets("SalesDataSheet").Range("C5") = Format(Sheets("SalesDataSheet").Range("B5"), "MMM yyyy")
Nicholas
  • 11
  • 5
0

To add a double quote (") in vba you need to type 4 double quote:

Sheets("SalesDataSheet").Range("C5") = "=TEXT(B5," & """" & "mmm yyy" & """" & ")"
genespos
  • 3,211
  • 6
  • 38
  • 70