1

I'm creating a function that inputs a formula into a cell. But I keep on receiving a syntax error. I know this is due to the quotation marks. I was wondering how I would go about including the quotation marks of the formula in the function without causing a syntax error.

Any help would be grateful.

Sub codedump()


      Range("A1").Value = "=Dump(GoogleAnalytics("ga:78770227", "ga:visits", "2014-05-28", "2014-06-26", "","", "", "", 500, FALSE, FALSE))"

End Sub
1
  • Escape it with two double quotes. So a string with a quotation mark would look like """" Commented Jun 27, 2014 at 14:57

3 Answers 3

4

Use escaping

For example, "" gives a quotation mark. Otherwise, use char codes

Sub codedump()

      Range("A1").Value = "=Dump(GoogleAnalytics(""ga:78770227"", ""ga:visits"", ""2014-05-28"", ""2014-06-26"", """","""", """", """", 500, FALSE, FALSE))"

End Sub

from http://msdn.microsoft.com/en-us/library/267k4fw5(v=vs.85).aspx

Alternatives:

'Escaping
Private Sub InsertQuote()
   TextBox1.Text = "She said, ""You deserve a treat!"" "
End Sub

'Character code
Private Sub InsertAscii()
   TextBox1.Text = "She said, " & Chr(34) & "You deserve a treat!" & Chr(34)
End Sub

'Defined string
Const quote As String = """"
TextBox1.Text = "She said, " & quote & "You deserve a treat!" & quote
Sign up to request clarification or add additional context in comments.

Comments

0

You'll need to wrap your quotation marks in quotation marks to get them to appear on the sheet. Something like:

Range("A1").Value = "=Dump(GoogleAnalytics(""ga:78770227"", ""ga:visits"", ""2014-05-28"", ""2014-06-26"", """","""", """", """", 500, FALSE, FALSE))"

should do the trick.

Comments

0

Use

 Chr(34) & Chr(34)

in place of

 ""

34 is the ASCII character code for " and VBA will convert Chr(34) to " when it builds your string.

2 Comments

VBA uses Unicode so ASCII character codes are not relevant. Of course, by design, Unicode is a superset of ASCII and uses the same character codes for the common characters.
Good to know. I usually just use the ASCII list because it's smaller and I don't need much other than what is in it. Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.