VBA Double Quotes in Strings: How to Escape a Quote

VBA & macros · Updated November 18, 2026

To include a double quote inside a VBA string, type two double quotes in a row: VBA treats "" inside a string as one literal quotation mark. For example, "She said ""Hello""" produces the text She said "Hello".

How VBA reads quotation marks in strings

In VBA, a string literal begins and ends with a straight double quote. The quotes that mark the start and end are not part of the resulting text; they tell VBA where the string begins and finishes. To represent a quotation mark as content rather than as a boundary, double it. This rule lets VBA distinguish a quote in the text from the quote that closes the string.

For instance, the literal "red" represents the three-letter word red, without quotation marks in the value. By contrast, """red""" represents the five-character text "red", including one quotation mark on each side. The extra pairs in the source are syntax; they do not mean that the displayed text will contain doubled quote marks.

VBA does not use the backslash as a string escape character. Writing \" does not escape a quote as it might in some other programming languages; the backslash is just another character, and the quote still affects the string boundary. Use doubled quotes or construct the quote character another way.

The basic doubled-quote method

For a short string, doubling the quote is usually the clearest approach. Each pair of adjacent double quotes inside the literal becomes one quotation mark in the resulting value. The following macro assigns a sentence to a variable and prints it in the Immediate window:

Sub ShowQuotedText()
    Dim message As String

    ' The doubled quotes become single quotes in the string value.
    message = "She said, ""Hello!"""
    Debug.Print message
End Sub

The output is She said, "Hello!". In the VBA editor, open the Immediate window to see output from Debug.Print. If you run a macro that changes workbook data, save a copy of the workbook first: macros cannot be undone with Ctrl+Z. Keep macros in a macro-enabled workbook, such as an .xlsm file, if you need to preserve them.

Count the quote marks by separating the string boundaries from the content. In the example, the first quote opens the literal. Two quotes represent the opening quote in the sentence. The final two quotes represent its closing quote, followed by the last quote that ends the literal. That can look crowded, but it is a consistent rule rather than a special case.

Practical examples of quoted text

Use the same method in assignments, messages, and cell values. These examples show the source code and the text each expression produces:

  • "The sign says ""Open""." produces The sign says "Open".
  • """Yes"" or ""No""?" produces "Yes" or "No"?
  • "He called it a ""quick fix""." produces He called it a "quick fix".

Here is a complete Excel example. It writes a value to cell A1; the quotation marks around the word Ready are part of the cell’s displayed text, not Excel formula syntax.

Sub WriteQuotedText()
    Dim target As Range

    ' Put literal quotation marks around the word in A1.
    Set target = ThisWorkbook.Worksheets("Sheet1").Range("A1")
    target.Value = "The status is ""Ready""."
End Sub

Replace Sheet1 with the name of a worksheet that exists in the workbook. If the worksheet name itself contains a space, that does not change how it is written inside the VBA string: the name remains enclosed by the string’s boundary quotes.

Using Chr$(34) to build strings

Another option is Chr$(34), which returns the character with code 34 in the current character set: the standard double quote. This is useful when a string contains many quotes or when a string is assembled from several pieces. The dollar sign requests a String return value; for this character, Chr$(34) is a common choice.

Sub BuildQuotedText()
    Dim quoteMark As String
    Dim message As String

    ' Chr$(34) supplies one double-quote character.
    quoteMark = Chr$(34)
    message = "The status is " & quoteMark & "Ready" & quoteMark
    Debug.Print message
End Sub

This also prints The status is "Ready". The ampersand joins string pieces together. In VBA, use & for string concatenation rather than relying on the plus sign, which can also participate in numeric addition and make an expression harder to interpret.

There is no single best method for every string. Doubled quotes are compact and familiar when there are only one or two quotation marks. A named variable such as quoteMark can make a long expression easier to scan, especially if several pieces are joined. Avoid replacing every quote with Chr$(34) automatically: a long chain of function calls may be less readable than the doubled-quote form.

Putting quotes inside an Excel formula

Excel formulas often contain their own quoted text, so a formula assigned from VBA has two layers to consider. The VBA string needs its boundary quotes, and every double quote that should appear in the formula text must be doubled inside that string. For example, Excel uses quotes around the text value Yes in this formula: =IF(B1="Yes","OK","No").

With a worksheet in A1 and the formula intended for that cell, the VBA assignment is:

Sub InsertFormulaWithText()
    Dim target As Range

    ' Doubled quotes in VBA become single quotes in the Excel formula.
    Set target = ThisWorkbook.Worksheets("Sheet1").Range("A1")
    target.Formula = "=IF(B1=""Yes"",""OK"",""No"")"
End Sub

The value assigned to target.Formula is the formula text =IF(B1="Yes","OK","No"). If B1 contains Yes, Excel evaluates the formula as OK; otherwise it returns No. A useful check is to read the formula string after mentally removing one quote from each doubled pair. If the result is not a valid Excel formula, the VBA escaping is not the only issue.

Do not confuse formula quotes with quotes used for worksheet names. In an Excel formula, a sheet name containing spaces is typically enclosed in single quotes, as in 'Quarter One'!A1. Those apostrophes are not VBA string delimiters, so they do not need doubling as double quotes. The whole formula is still enclosed in VBA double quotes, and any double quotes inside the formula text still need to be doubled.

Common quote-related errors

A missing or extra quote can cause a compile error, such as VBA reporting that it expected the end of a statement. In other cases, the code compiles but produces text that is not what you intended. These checks help narrow down the problem:

  • Check the string boundaries. Make sure each literal has an opening and closing quote. A quote meant to appear in the result must be doubled inside those boundaries.
  • Do not use backslash escaping. \" is not VBA’s way to insert a quote. Use a doubled quote or Chr$(34).
  • Use straight quotes in code. Curly typographic marks such as “ and ” are not substitutes for the straight quote character used by VBA syntax. They can appear as text only if included as actual characters within a correctly delimited string.
  • Separate VBA syntax from formula syntax. A string can be valid VBA but contain an invalid Excel formula. Check the resulting formula text independently.
  • Watch for a quote at the end. A literal meant to end with a quote needs a doubled quote for the content and another quote to close the literal.

When a complicated assignment is hard to inspect, build it in pieces and print the result before using it. For example, assign sections to a String variable, join them with &, and use Debug.Print to examine the exact output. This separates a VBA parsing issue from a mistake in the text or formula being assembled.

Choosing a clear method and checking the result

For a single sentence, put the doubled quotes directly in the literal. For repeated or dynamically assembled quote characters, consider storing Chr$(34) in a clearly named String variable. The key is maintainability: another person should be able to tell which quotes are syntax and which ones will appear in the output.

Test a string in a small, controlled way before inserting it into a larger macro. Debug.Print is useful for inspecting text in the Immediate window. A worksheet cell can also show the result, though a cell may not make trailing spaces or line breaks obvious. If you are generating a formula, inspect the assigned formula in the formula bar or print the string and compare it with the formula you would enter directly in Excel.

VBA macros run in desktop Excel for Windows and Mac, but Excel for the web cannot run VBA macros. The quote-doubling rule belongs to VBA itself and does not change between those desktop platforms. If your workbook must work in a browser, consider whether the task can be done with worksheet formulas or another supported automation option instead.

Frequently Asked Questions

How do I put a double quote in a VBA string?
Type two consecutive double quotes inside the string literal. For example, """Hi""" represents the text "Hi", including the quotation marks.

Does VBA use a backslash to escape quotes?
No. A backslash does not escape a quote in VBA. Double the quote mark, or use Chr$(34) to create a quote character.

What does four double quotes mean in VBA?
The literal """" produces one double-quote character. The first and last quotes delimit the string, and the two middle quotes represent the character inside it.

How do I add quotes around a variable’s value?
Join the variable with a quote character before and after it. You can use doubled quotes in a string expression or store Chr$(34) in a String variable, then concatenate with &.

Why does a VBA string work but the Excel formula fail?
VBA parsing and Excel formula parsing are separate. After VBA removes the extra quote marks, the remaining text must still be a valid formula for Excel. Print or inspect the final formula string to find which layer needs correction.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.