Excel VBA: Add Double Quotes to a String in VBA Code

VBA & macros · Updated November 21, 2026

To add double quotes around a string in Excel VBA, concatenate a quote character before and after the text: Chr(34) & text & Chr(34). You can also write the quote character inside a VBA string literal by doubling it, as in """" & text & """".

What VBA means by a double quote

In VBA, double quotes have two roles: they mark the beginning and end of a string literal, and they can also be characters contained in a string. For example, "Hello" is a string whose value is Hello; the quote marks delimit the value and are not part of it. To put actual quote characters into the value, you have to represent them explicitly.

The character most people mean is the straight double quote, Unicode U+0022. A curly quote such as “ or ” is a different character and will not behave like the normal quote used in VBA syntax. If the result will be read by another program or saved as data, use the straight character unless that program specifically expects typographic quotation marks.

VBA joins strings with the ampersand operator (&). This makes the basic construction easy to read: one quote character, the original text, then another quote character. It creates a new string value; it does not change the rules for how VBA parses the source code around that expression.

Three ways to represent a quote character

For most code, Chr(34) is the clearest way to request a straight double quote by its character code. The dollar-sign form, Chr$(34), also returns a string and is commonly used in VBA. Either works for this task. The value 34 is the character code for the straight double quote in the character set used by these VBA functions.

The alternative is to double a quote inside a string literal. In VBA, two consecutive quotation marks inside a quoted literal represent one actual quote. Therefore, four quote marks in a row make a string containing one quote: the first and last marks delimit the literal, and the two between them represent its contents. That is why this expression wraps text in quotes:

"""" & text & """"

Both approaches produce the same result. Choose Chr$(34) when you want the code to make the character choice obvious, especially in a longer expression. Choose doubled quotation marks if the literal is short and your team finds that style easy to read. Avoid mixing several quoting styles in one expression unless it improves clarity.

Wrap a value in quotes in a macro

This example reads ordinary text from A1 on Sheet1, adds a quote at each end, and writes the result to B1. It assumes A1 contains a normal text value rather than an Excel error value. The source cell is left unchanged.

Sub PutQuotesAroundCellText()
    Dim sourceText As String
    Dim quotedText As String

    ' Read the text and add a straight quote at each end.
    sourceText = CStr(Worksheets("Sheet1").Range("A1").Value2)
    quotedText = Chr$(34) & sourceText & Chr$(34)
    Worksheets("Sheet1").Range("B1").Value = quotedText
End Sub

For example, if A1 contains Northwind, B1 receives the text "Northwind", including the two quote characters. The quotes are part of B1’s value; they are not just visual formatting. If you need the original value for calculations or sorting, keeping the quoted output in a separate cell is usually safer than replacing the source.

To enter and run VBA in desktop Excel for Microsoft 365 on Windows, open the Visual Basic Editor with Alt+F11, insert a standard module, and paste the procedure there. On a Mac, Option+F11 may open the editor; some keyboards require Fn as well. Excel for the web cannot create or run VBA macros, so use desktop Excel. Before running a macro, save a copy of the workbook. Macro changes cannot be undone with Ctrl+Z.

Put quotes inside a VBA string literal

If you are writing a fixed string directly in VBA code, double each quote that should appear in the resulting text. For example, this assignment creates the text She said “Hello” using straight quote characters around Hello:

Sub MakeQuotedSentence()
    Dim message As String

    ' Doubled quote marks become quote characters in the value.
    message = "She said ""Hello"""
    MsgBox message
End Sub

The outer quote marks begin and end the VBA literal. Each pair of doubled marks inside it contributes one quote to the value. This is the common source of confusion: adding a quote to the code is not always the same as adding a quote to the string. If the literal becomes difficult to count, build it with Chr$(34) instead:

Sub MakeSentenceWithChr()
    Dim message As String

    ' Assemble the same sentence using the quote character code.
    message = "She said " & Chr$(34) & "Hello" & Chr$(34)
    MsgBox message
End Sub

These are two alternatives, not steps to perform together. Both display the same sentence. The Chr$ version can be easier to edit when the string contains many quote marks, while doubled quotes are compact for a short fixed literal.

Escape quotes already present in the text

Wrapping a string in quotes and escaping quotes within its content are different operations. Suppose a value is She said "go". Simply adding a quote at the beginning and end produces "She said "go"". That output has the original inner quotes unchanged. It may be fine for display, but it is not correctly escaped for formats that use quotes to enclose fields.

For a CSV-style field, embedded quote characters are normally doubled, and the whole field is enclosed in quotes. This macro demonstrates both operations for a single text value:

Sub MakeCsvStyleField()
    Dim sourceText As String
    Dim csvField As String

    ' Double embedded quotes, then enclose the field in quotes.
    sourceText = "She said ""go"""
    csvField = Chr$(34) & Replace(sourceText, Chr$(34), _
        Chr$(34) & Chr$(34)) & Chr$(34)
    MsgBox csvField
End Sub

For the sample value, the result is "She said ""go""": the outer quotes mark the field, while each quote within the original text appears twice. CSV also needs quoting when a field contains a comma or a line break. This example illustrates the quote-escaping rule, but it is not a complete CSV export routine for a worksheet. When exporting a workbook, Excel’s Save As CSV options are usually preferable to manually adding quote characters to every cell.

Choose the right method for the job

The best method depends on what the receiving application expects. Adding quote characters can be appropriate when a downstream text format requires them, but it is not a general way to format a cell. A cell containing the text "125" is different from a numeric cell containing 125: the former includes quote characters in its text value, while the latter can be used directly in arithmetic.

  • For a visible text result: build a separate output string with Chr$(34) & text & Chr$(34).
  • For a fixed VBA message: double the quote marks inside the string literal, or assemble the message with Chr$(34).
  • For CSV-compatible field text: double embedded quotes and enclose the field, while also accounting for commas and line breaks.
  • For a worksheet display change only: consider a number format or another display method instead of changing the underlying value.

It is also worth distinguishing quote characters from Excel’s formula bar display and from the quotation marks used in formula syntax. VBA’s string concatenation creates text. It does not set a cell’s number format, convert text into a number, or guarantee that a complete file will follow a particular data-exchange standard.

Common mistakes and how to avoid them

  • Using only one quote mark in the expression: a quote inside a VBA literal must be doubled, or supplied as a character with Chr$(34). Otherwise, VBA may treat it as the end of the literal and report a compile error.
  • Confusing code notation with the result: """" in VBA source represents one quote character. It does not put four quote characters into the output.
  • Using curly quotes in code: smart punctuation copied from a document is not a substitute for straight VBA string delimiters. Re-type the quote marks in the Visual Basic Editor if the code will not compile.
  • Wrapping a value more than once: running a macro that edits a cell in place repeatedly can produce additional layers of quote marks. Write to a separate output range, or check whether the value is already wrapped before changing it.
  • Assuming quotes make a CSV export safe: an embedded quote must be doubled, and commas and line breaks can also require field quoting. Adding a quote at each end alone does not handle every export case.
  • Overlooking non-text values: CStr converts many values to text, but an Excel error value cannot be treated as ordinary text this way. Check for errors first if the source range may contain them.

When debugging, inspect the value in a cell or display it in a message box so you can see where the quote characters actually occur. If a procedure does not compile, check that every string literal has matching delimiters and that embedded quote marks are doubled. Also confirm the macro is in a standard module if you expect to run it from Excel’s macro list.

Working safely with macro-generated text

A macro that changes cell values is a data edit, even if the change looks like punctuation. Keep an untouched source column or make a workbook copy before a bulk operation. This is especially useful when the text will later be imported into a database, compared with another list, or used in formulas: inserted quotes may make otherwise matching values different.

VBA macros require a macro-enabled workbook format such as .xlsm if you want to preserve the code. Excel may also restrict macros according to the file’s source and the organization’s security settings. Enable macros only for workbooks you trust, and do not treat a request to enable macros as proof that a file is safe. Excel for the web can display a workbook containing macros, but it does not execute VBA.

If you only need to prepare a text export, consider whether Excel’s built-in CSV export already meets the requirement. If another program expects a custom quoting convention, verify that program’s specification and test a few representative values, including text with quotes, commas, and line breaks. Correct escaping depends on the format being produced, not merely on the fact that the output is called a text file.

Frequently Asked Questions

How do I add double quotes around a string in VBA?
Concatenate the quote character on both sides: Chr$(34) & text & Chr$(34). You can also use doubled quotation marks as string literals: """" & text & """".

What does four double quotes mean in VBA?
In a VBA string literal, four consecutive quote marks, """", represent a string containing one straight double-quote character. The outer pair delimits the literal, and the inner pair represents the character.

How do I put quotation marks inside a VBA string?
Double the quote character inside the literal. For example, "She said ""yes""" evaluates to She said "yes". You can also concatenate Chr$(34) around or within the text.

Is Chr(34) the same as Chr$(34)?
For this purpose, both produce the straight quote character with code 34. Chr$ explicitly returns a string, which suits string concatenation; Chr is also valid VBA and is often converted to text when joined with a string.

Can I run an Excel VBA macro in Excel for the web?
No. Excel for the web does not create or run VBA macros. Open the workbook in desktop Excel for Windows or Mac to use the Visual Basic Editor and run VBA code.

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.