VBA Include Quotes in a String: Examples and Fixes

VBA & macros · Updated November 18, 2026

To include a double quotation mark inside a VBA string, double it in the string literal: write message = "She said ""Hello.""" to produce She said "Hello.". You can also add a quote character with Chr$(34), which is useful when you are assembling text from several parts.

How VBA represents strings

In VBA, a string literal begins and ends with a straight double quotation mark. The marks at the ends tell VBA where the text value starts and stops; they are not normally included in the value itself. For example, "Good morning" represents the text Good morning, without quotation marks around it.

That creates an apparent puzzle when the text you want to store needs quotation marks of its own. VBA has to distinguish the quotation mark that belongs to the text from the one that closes the literal. Its standard rule is to represent a quotation mark inside a literal with two consecutive quotation marks. VBA reads those two source characters as one quote in the resulting string.

This is a rule for VBA source code, not a special feature of Excel cells. Once the string is created, it is an ordinary text value. You can assign it to a variable, display it in a message box, write it to a worksheet, or pass it to another procedure.

Double quotes inside a string literal

Doubling the quotation mark is usually the clearest approach when the text is fixed and you can see the whole phrase in the code. In the example below, each pair of adjacent inner marks becomes one literal quote, while the first and last marks delimit the string:

Sub ShowQuotedText()
    Dim message As String

    ' Double each quote that should appear in the message.
    message = "She said ""Hello."""
    MsgBox message
End Sub

The message box displays She said "Hello.". Notice that the period is inside the quoted word in this example. Moving the period in the source changes the output, so count the opening and closing marks carefully when copying or editing a line.

Here are some common patterns and the text each one creates:

  • text = "Use ""quoted text"" here." creates Use "quoted text" here..
  • text = """ creates a string containing one quotation mark. The four marks are the opening delimiter, a doubled quote for the value, and the closing delimiter.
  • text = """word""" creates "word", including a quote before and after the word.

The final pattern is easy to miscount because the source has three quotation marks at each end. Read each group from left to right: the first mark opens the literal, the next two represent a quote in the value, and the final mark closes the literal.

Use Chr$(34) to add a quote character

Chr$(34) returns a one-character string containing the double quotation mark. The number 34 is the character code for that mark in the character set used by VBA’s Chr function. The dollar sign in Chr$ indicates a string-returning version of the function; Chr(34) is also commonly used to get the character.

This approach can make a long expression easier to scan when the text contains many quotation marks or when quote marks are being added around variable data:

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

    ' Store one double quotation mark for reuse.
    quoteMark = Chr$(34)
    message = "The status is " & quoteMark & "Ready" & quoteMark & "."
    MsgBox message
End Sub

The displayed result is The status is "Ready".. This method separates the quote character from the surrounding words, which can be helpful in a complicated expression. For a short, fixed phrase, doubled quotes are often more compact and easier for someone else to read. Neither method changes the final string; they are two ways to express the same character.

Combine quoted text with variables

Use the ampersand operator, &, to join string pieces. It is especially useful when the text between quotation marks comes from a variable, a cell, or a user’s input. For example, you can put a name inside quotation marks without hard-coding the name into the literal:

Sub QuoteAName()
    Dim personName As String
    Dim quoteMark As String
    Dim message As String

    ' Set an example name and the quote character.
    personName = "Mina"
    quoteMark = Chr$(34)
    message = "The name is " & quoteMark & personName & quoteMark & "."
    MsgBox message
End Sub

The result is The name is "Mina".. You could write the same pattern with doubled quotes around fixed portions, but a named quoteMark variable makes the assembly more apparent when the expression grows. If the variable may contain an empty value, the expression still adds the surrounding quotes; check the input first if empty names should not be quoted.

Prefer & for string concatenation rather than relying on the plus sign. In VBA, + can also mean numeric addition, so expressions involving numbers can be harder to interpret or can produce a different result than intended. The ampersand states that the pieces should be joined as text. When values can be Null or have unexpected types, handle those cases deliberately rather than assuming every value can safely be combined.

Put a string containing quotes in a worksheet

After building the text, assign it to a cell’s Value property just as you would any other string. The quote marks in the value are not removed merely because they are written to Excel. This example places the result in cell A1 of a worksheet named Sheet1:

Sub WriteQuotedText()
    Dim message As String

    ' Create a message with quotation marks in its value.
    message = "The status is ""Ready""."
    ThisWorkbook.Worksheets("Sheet1").Range("A1").Value = message
End Sub

Before running a macro, save a copy of the workbook. Macros can change workbook contents, and their actions cannot be reversed with Ctrl+Z. Check that the worksheet name exists in the workbook; if it does not, the procedure will stop with a run-time error. If the code is intended to use the currently active workbook rather than the workbook containing the macro, choose the workbook reference intentionally instead of changing it by guesswork.

VBA source code, worksheet values, and worksheet formulas are different contexts. A string written into a cell is displayed as text; the doubled quotes belong to the VBA code and the cell receives a single quote character at each intended position. If you type a formula into a cell, that formula has its own quoting rules. Do not copy the doubled-quote notation into a cell expecting it to behave as VBA code.

Common quote-related errors

Most quote problems come from an unmatched delimiter or from using the conventions of another language. When VBA cannot find the end of a string, it may highlight a line or report a compile error even if the actual missing mark is earlier in the statement. Check the full expression, not just the word shown by the editor.

  • Using a single quote to quote text: In VBA, a single apostrophe starts a comment when used in code outside a string. It does not replace the double quotation marks required around a string literal.
  • Escaping with a backslash: A backslash is not VBA’s standard way to escape a quote. Writing \" as you might in another language does not produce the intended VBA string. Double the quote or use Chr$(34).
  • Leaving out one mark in a doubled pair: A quote intended as data must be represented by two adjacent quotation marks inside the literal. One mark may close the string too early.
  • Confusing visible source with output: The VBA editor shows two marks for one embedded quote. The resulting message or cell contains one. That difference is expected, not duplicated output.
  • Using typographic quotation marks: Curly marks such as “ and ” are different characters from the straight quotation mark used to delimit VBA strings. Use straight marks in code.

When a line is difficult to count, temporarily build the message in short pieces, or assign Chr$(34) to a clearly named variable. You can also inspect a value by displaying it in a message box or writing it to a cell. For strings with leading or trailing spaces, remember that those spaces are part of the value even if they are difficult to see in a message box.

Which method should you choose?

Choose based on how the string is constructed, rather than on a difference in output. Both methods produce the same quote character, but one may be easier to maintain in a particular line of code.

  • Use doubled quotes for a short, fixed phrase. It keeps the complete text together and makes the intended wording easy to read.
  • Use Chr$(34) when you are inserting quotes around variable values, adding several quote characters, or finding a long run of doubled marks hard to follow.
  • Use a named constant or variable if the same quote character is used repeatedly in a longer procedure. A clear name can explain why the character is being added.
  • Use the format required by the destination when creating data for another system. VBA string syntax only determines how VBA builds the text; it does not automatically apply CSV, JSON, SQL, or other formats’ escaping rules.

That last distinction matters. For example, doubling a quote in a VBA literal allows the program to create a quote character, but a CSV field containing quotes has its own formatting convention. Likewise, valid VBA text is not necessarily safe or valid input for a database query or a JSON document. Follow the destination format’s rules separately, especially when the text includes user-provided data.

Where to enter and run the VBA code

In Excel for Microsoft 365 on Windows, open the Visual Basic Editor with Alt+F11. You can also use the Developer tab and choose Visual Basic. In the editor, choose Insert > Module, paste a complete procedure into the module, and run it with F5 while the cursor is inside that procedure. If the Developer tab is hidden, enable it through File > Options > Customize Ribbon and select Developer.

On Excel for Mac, the Visual Basic Editor is available from Tools > Macro > Visual Basic Editor or from the Developer tab when it is shown. The keyboard shortcut is generally Option+F11; depending on the keyboard, you may also need to hold Fn. The ribbon and shortcut can vary with Mac settings. Excel for the web does not run VBA macros, so use the desktop application to execute this code.

Save a workbook that contains VBA in a macro-enabled format such as .xlsm if you need to retain its macros. Follow your organization’s macro security rules and only run code you trust. The examples here are short, but the general precaution still applies: save a backup before running any procedure that could make changes.

Frequently Asked Questions

How do I put one double quote in a VBA string?
Use four quotation marks in the literal: quoteMark = """". The first and last delimit the literal, and the middle pair represents the one quote in the value. You can also use Chr$(34).

Does VBA use a backslash to escape quotation marks?
No. For a quote inside a VBA string literal, double the quote. A backslash escape such as \" is not the standard VBA string-literal rule.

What is the difference between Chr(34) and Chr$(34)?
Both are used to obtain the double-quote character. Chr$ returns a String, while Chr is the non-dollar-suffixed form. In typical string-building code, either is commonly seen; Chr$(34) makes the string return type explicit.

Why are there more quotation marks in my VBA code than in the result?
VBA uses doubled marks in source code to represent one quote in the string value. The extra mark is part of the notation, not a second character that will necessarily appear in the output.

Can I use single quotes around a VBA string?
No. String literals in VBA use double quotation marks. A single apostrophe is used to begin a code comment outside a string, so it cannot serve as a substitute for the string delimiters.

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.