Excel VBA Double Quotes in Strings: How to Write Them

VBA & macros · Updated November 21, 2026

In Excel VBA, put a literal double quote inside a string by writing two double quotes next to each other: "". For example, "She said ""Hello.""" becomes the text She said "Hello."; this rule also matters when VBA builds an Excel formula that itself contains quoted text.

The VBA rule for double quotes

VBA uses a double quote to mark the beginning and end of a string literal. When VBA encounters a quote inside that literal, it needs a way to distinguish a quote you want in the text from the quote that ends the literal. The convention is to double the quote: two consecutive quotation marks inside the string represent one quotation mark in the resulting text.

For example, the source code "The word ""Excel"" is quoted." contains three quoted sections visually, but it is one string literal. The doubled pairs in the middle become ordinary quote characters. The final, single quotation mark closes the string. This is the same basic syntax in Excel VBA for Microsoft 365 on Windows and in VBA on Mac.

VBA does not use a backslash to escape a quote. Typing \" is not the VBA equivalent of a quote escape; a backslash is just another character in a VBA string. This differs from languages that use backslash escapes, so examples copied from JavaScript, Python, or other languages can produce confusing results.

A short example you can use

Assign a string to a variable or a cell using doubled quotes wherever the resulting text needs a quote character. This example displays a message box, then writes the same text to cell A1:

Option Explicit

Sub ShowQuotedText()
    Dim message As String

    ' Two quote marks in the literal produce one in the displayed text.
    message = "She said ""Hello."""
    MsgBox message
    ThisWorkbook.Worksheets(1).Range("A1").Value = message
End Sub

The message shown and the value written to A1 are both She said "Hello.". The quotes around message in the assignment delimit the VBA string; the doubled quote pairs are the characters that appear in the result. Before running a macro, save a copy of the workbook. Changes made by VBA macros generally cannot be reversed with Ctrl+Z, and the same limitation applies to the Mac Undo shortcut, Command+Z.

How VBA reads a quoted string

It can help to separate the code you type from the text VBA creates. In a string literal, the first quotation mark opens the string, and the last undoubled quotation mark closes it. Within those boundaries, each doubled pair becomes a single quote in the value. Ordinary characters, spaces, punctuation, and line breaks are handled as part of the string according to how the literal is written.

Consider this assignment: label = "Status: ""Ready""". The value begins with the words and space Status: , followed by a quote, the word Ready, and a closing quote. A common source of errors is counting by eye without identifying which quote pairs are embedded and which single quote ends the literal. Read from left to right and look for the final closing quote.

VBA strings are delimited with straight ASCII quotation marks, not typographic “curly quotes.” If code is copied from formatted text and contains curly quotation marks, the VBA editor may not recognize them as string delimiters. Replace them with straight quotes typed in the editor. This is a source-code issue, not a setting in the Excel worksheet.

Putting quotes in an Excel formula

When VBA assigns a formula to a cell, two syntaxes are involved: the VBA string syntax and Excel formula syntax. The outer VBA string must be valid first; after VBA evaluates it, the resulting text must be a valid formula. Any quote character required by the formula has to be doubled in the VBA source.

This macro puts an IF formula in B2. The formula tests whether A2 contains the word Yes and returns Approved or Review:

Option Explicit

Sub WriteFormulaWithQuotedText()
    Dim target As Range

    ' Save a copy of the workbook before running a macro.
    Set target = ThisWorkbook.Worksheets(1).Range("B2")
    target.Formula = "=IF(A2=""Yes"",""Approved"",""Review"")"
End Sub

After VBA processes the doubled quotation marks, Excel receives =IF(A2="Yes","Approved","Review"). Excel then interprets the quoted words as text values in the formula. The quote characters surrounding the entire VBA expression do not appear in the formula; the doubled ones become the formula’s own quote characters.

The example uses Range.Formula, which accepts a formula in Excel’s macro-language form. A formula’s argument separator can vary with regional settings when entered directly in the grid, but VBA’s Formula property uses the macro-language form with commas. If your macro is intended to put a literal string beginning with an equals sign into a cell rather than calculate a formula, assign it as a value instead of using the Formula property.

Using Chr$(34) as an alternative

Another way to create a double quote is Chr$(34). The number 34 is the character code for the straight double quotation mark in the character set used by VBA. This can make a long string easier to read when it contains many quotes, although repeated concatenation can make simple strings harder to follow.

Option Explicit

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

    ' Chr$(34) returns a double-quote character.
    quoteMark = Chr$(34)
    message = "She said " & quoteMark & "Hello." & quoteMark
    MsgBox message
End Sub

The result is still She said "Hello.". In HTML, the ampersand in this code block is written as & so the fragment displays the VBA concatenation operator; in the VBA editor, use the ordinary ampersand character. The operator joins strings. Use Chr$ when it improves clarity, not because VBA requires it: doubling quotes is the standard, direct method.

You can also write a quote-only constant as Const quoteMark As String = """", but the run of four quote characters can be difficult to scan. A named variable assigned with Chr$(34) may be clearer for that case. Both approaches produce a one-character string containing a double quote.

Choosing a method for common tasks

For a short message or a quoted word, doubled quotes are usually the clearest choice. They keep the complete text in one literal and make the output predictable. For a formula with a few quoted text values, doubling is also conventional; check the formula after assignment if the expression is long or generated from several pieces.

  • Writing a fixed message: Use doubled quotes directly, such as "Enter ""Yes"" to continue.".
  • Building text from changing values: Join the fixed parts and variables with &, placing doubled quotes in the fixed parts where needed.
  • Several quote characters in a constructed string: Consider assigning Chr$(34) to a clearly named variable and concatenating it.
  • Writing an Excel formula: First identify the formula text Excel must receive, then double every quote required inside that formula’s VBA string.

When a value comes from a cell, do not put the value itself inside a VBA string literal unless you specifically want fixed text. Read it into a variable and concatenate it where appropriate. For instance, to create a greeting from a name in A1, build the fixed quoted portions separately from the cell value. This reduces accidental quoting errors and makes it easier to tell which parts are data and which are VBA syntax.

Common quote errors and how to fix them

A compile error such as “Expected: end of statement” often means VBA interpreted a quote as the end of the string earlier than intended. Find the first quote in the line that should appear in the output and make sure it is doubled in the source literal. Also verify that the string has a closing quote after all embedded quote pairs.

Another frequent mistake is adding an extra quote at the end. Each embedded quote requires a pair, but the string still needs its own closing delimiter. In "A ""quoted"" word", the pair before quoted creates the opening output quote, the pair after the word creates the closing output quote, and the final single quote closes the VBA literal. Counting those roles can reveal a missing or surplus mark.

  • If the output contains two quote marks where you expected one, inspect whether the resulting string includes an unintended extra character.
  • If Excel reports a formula error, inspect the formula Excel received, not just the VBA source. The formula may be missing a quote or may have a separate syntax problem.
  • If the editor highlights a line unexpectedly, replace curly quotation marks with straight quotes and check for an unclosed string on the preceding line.
  • If a backslash appears in the output, remove it unless the backslash is genuinely part of the desired text.

Inspecting the result while debugging

When a long expression is hard to reason about, assign it to a variable first and inspect the variable before using it. In the Visual Basic Editor, press Ctrl+G on Windows to show the Immediate window, then use Debug.Print message in your procedure to print the value there. On a Mac, the Visual Basic Editor shortcut and function-key behavior can depend on the keyboard and macOS settings; use the editor’s View menu to open the Immediate window if the Windows shortcut is unavailable.

For a formula, inspect the cell’s Formula property in the Immediate window or select the cell and examine its formula in Excel. The key diagnostic question is: what exact characters did VBA pass to Excel? If the formula text looks right but Excel still rejects it, investigate other formula issues such as a misspelled function name, an invalid reference, or separators, rather than changing quote escaping blindly.

When a macro changes a workbook, save a backup copy before running it. Excel’s normal Undo history does not provide a reliable way to reverse VBA changes. If you are developing a macro, test it on a copied worksheet or a small sample range before applying it to important data.

Frequently Asked Questions

How do I put quotation marks inside a VBA string?
Write each quotation mark you want in the result as two consecutive quotation marks inside the string literal. For example, """Hi""" produces "Hi".

Does VBA use a backslash to escape double quotes?
No. VBA uses doubled double quotes inside a string literal. A backslash does not escape a quote in VBA; it is treated as an ordinary character.

How do I add quotes around text in an Excel formula from VBA?
Write the formula as a VBA string and double the quote marks the formula needs. For example, the VBA source "=IF(A1=""Yes"",""OK"",""No"")" becomes the formula =IF(A1="Yes","OK","No").

Can I use Chr(34) instead of doubled quotes?
Yes. Chr$(34) returns a double-quote character, which you can join to other text with &. Doubling quotes is usually simpler for a short, fixed string; Chr$ can help make a longer construction easier to read.

Why does my VBA string give a compile error?
Common causes include a missing closing quote, an embedded quote that was not doubled, or curly quotation marks copied from formatted text. Replace curly quotes with straight ones and check the string from left to right, identifying embedded pairs and the final closing delimiter.

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.