Excel Formula for Converting Smart Quotes to Straight Quotes

📅 May 08, 2026 📝 Sarah Miller

Writing code in Excel often leads to frustrating syntax errors when "smart quotes" (“ ”) silently break your formulas. While teams typically rely on standard IT funding sources to acquire specialized development software, optimizing your existing environment grants immediate, zero-cost programming efficiency. Under the stipulation that Excel's compiler strictly requires standard straight quotes, you must systematically clean pasted text. For example, code copied from Microsoft Word or Teams often imports these corrupting curly characters. Below, we outline how to utilize a nested SUBSTITUTE formula to automatically purge smart quotes and restore executable code.

Excel Formula for Converting Smart Quotes to Straight Quotes

If you have ever used Microsoft Excel to build database queries, generate JSON strings, draft HTML snippets, or write code templates, you have likely run into one of the most frustrating hidden bugs in modern word processing: smart quotes.

Excel, along with many other Microsoft Office applications, loves to be helpful. When you type a standard straight single quote (') or double quote ("), the application's auto-formatting engine often intercepts it. It automatically converts these clean, developer-friendly straight marks into styled, angled "curly" or "smart" quotes (, ', , and ).

While smart quotes look great in a word document or a PDF report, they are a complete disaster for code. Databases, compilers, interpreters, and web browsers do not recognize them as string delimiters. To a SQL engine or a Python interpreter, a curly quote is just an invalid, unrecognized character that will cause your code to crash immediately with syntax errors. Fortunately, you can build a powerful, nested Excel formula to clean your text and replace these problematic curly quotes with standard, compiler-approved straight quotes.

The Core Problem: Straight vs. Smart Quotes

Before writing the formula, it is important to understand what we are replacing. Computers identify characters by their underlying numeric codes. Standard straight quotes are basic ASCII characters, while smart quotes belong to the extended Unicode character set:

Character Name Visual Glyph ASCII / Unicode Code Code Status
Straight Double Quote " ASCII 34 Safe (Valid for Code)
Straight Single Quote (Apostrophe) ' ASCII 39 Safe (Valid for Code)
Left Double Curly Quote Unicode 8220 (U+201C) Unsafe (Breaks Code)
Right Double Curly Quote Unicode 8221 (U+201D) Unsafe (Breaks Code)
Left Single Curly Quote Unicode 8216 (U+2018) Unsafe (Breaks Code)
Right Single Curly Quote ' Unicode 8217 (U+2019) Unsafe (Breaks Code)

When you copy text that was generated in Excel or copied from a web browser, Slack, or Microsoft Word, these characters are often mixed together. To programmatically clean this data in Excel, we must target all four variants of the smart quotes and convert them to their straight equivalents.

The Excel Formula: Nested SUBSTITUTE

To replace characters in a text string in Excel, we use the SUBSTITUTE function. The syntax for the function is simple:

=SUBSTITUTE(text, old_text, new_text)

To clean all four types of curly quotes, we must nest four separate SUBSTITUTE functions inside one another. This passes the output of one replacement as the input for the next. Here is the standard nested formula designed to clean a text string in cell A2:

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2, "“", """"), "”", """"), "‘", "'"), "'", "'")

Breaking Down the Formula

It can be tough to read nested formulas, so let's break down each layer from the inside out to see exactly how it processes your text:

  • Step 1 (Inner-most): SUBSTITUTE(A2, "“", """")
    This identifies the opening double curly quote () and replaces it with a straight double quote. You will notice four double quotes in a row (""""). In Excel formulas, to represent a single literal double quote inside text, you must escape it by doubling it up. The outer two quotes wrap the string, while the inner two tell Excel to output a single straight quote.
  • Step 2: SUBSTITUTE([Result of Step 1], "”", """")
    This takes the cleaned text and replaces the closing double curly quote () with a standard straight double quote.
  • Step 3: SUBSTITUTE([Result of Step 2], "‘", "'")
    Next, we target the opening single curly quote () and replace it with a standard straight single quote ('). Because we are outputting a single quote, we can simply wrap it in standard double quotes ("'").
  • Step 4 (Outer-most): SUBSTITUTE([Result of Step 3], "'", "'")
    Finally, the formula finds the closing single curly quote (or apostrophe) (') and replaces it with a standard straight single quote.

A More Reliable Approach: Using CHAR and UNICHAR

While the formula above works perfectly in most environments, copy-pasting raw curly quotes into your Excel formula bar can sometimes fail. Depending on your system's region settings, language profile, or keyboard layout, Excel might not recognize the raw curly quote characters you pasted into the formula window.

To make your formula completely robust, reliable across different locales, and immune to auto-formatting glitches, you can use numeric character codes instead of copy-pasting the actual symbols. We do this by utilizing the CHAR and UNICHAR functions.

  • CHAR(34) generates a straight double quote (").
  • CHAR(39) generates a straight single quote (').
  • UNICHAR(8216) represents the opening single curly quote ().
  • UNICHAR(8217) represents the closing single curly quote (').
  • UNICHAR(8220) represents the opening double curly quote ().
  • UNICHAR(8221) represents the closing double curly quote ().

By substituting these functions into our nested formula, we get a highly professional, bulletproof solution:

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2, UNICHAR(8220), CHAR(34)), UNICHAR(8221), CHAR(34)), UNICHAR(8216), CHAR(39)), UNICHAR(8217), CHAR(39))

This formula functions identically to the previous version, but it is much easier to read and troubleshoot because it does not rely on visually distinguishing between different shapes of quote marks inside your formula bar.

Real-World Example: Fixing Concatenated SQL Statements

Let's look at a practical scenario where this formula is a lifesaver. Imagine you are using Excel to write a batch of SQL update statements by concatenating values from columns:

In cell A2, you have a name: O'Connor (using a smart right apostrophe).
In cell B2, you have a department: “Engineering” (copied from an internal document with smart double quotes).

You use this concatenation formula in cell C2 to generate your SQL statement:

="UPDATE users SET dept = '" & B2 & "' WHERE last_name = '" & A2 & "';"

The resulting output in C2 looks like this:

UPDATE users SET dept = '“Engineering”' WHERE last_name = 'O'Connor';

If you run this directly in a database like MySQL or PostgreSQL, the query will crash because of the curly characters surrounding Engineering and the curly apostrophe in O'Connor. To solve this automatically, wrap your entire concatenation formula inside our cleaning formula:

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE("UPDATE users SET dept = '" & B2 & "' WHERE last_name = '" & A2 & "';", UNICHAR(8220), CHAR(34)), UNICHAR(8221), CHAR(34)), UNICHAR(8216), CHAR(39)), UNICHAR(8217), CHAR(39))

With this wrapper, your output instantly transforms into valid, production-ready SQL:

UPDATE users SET dept = '"Engineering"' WHERE last_name = 'O'Connor';

Automating Cleanups with a VBA Macro

If you have large datasets or find yourself needing to fix smart quotes on a daily basis, typing or copying nested formulas can become tedious. You can build a custom User-Defined Function (UDF) in VBA to automate this task with a single, clean formula command.

To set this up, follow these quick steps:

  1. Press ALT + F11 to open the VBA Editor in Excel.
  2. Click Insert > Module from the top menu.
  3. Copy and paste the following VBA code into the module window:
Function CleanSmartQuotes(ByVal TargetText As String) As String
    Dim result As String
    result = TargetText
    
    ' Replace double smart quotes
    result = Replace(result, ChrW(8220), Chr(34))
    result = Replace(result, ChrW(8221), Chr(34))
    
    ' Replace single smart quotes
    result = Replace(result, ChrW(8216), Chr(39))
    result = Replace(result, ChrW(8217), Chr(39))
    
    CleanSmartQuotes = result
End Function

Once saved, you can use your custom function anywhere in your workbook just like any native Excel formula. In cell B2, you can simply write:

=CleanSmartQuotes(A2)

This keeps your worksheets tidy, easy to read, and simple to maintain for teammates who might find long nested formulas intimidating.

Proactive Prevention: Disabling Smart Quotes in Excel

While fixing smart quotes using formulas is highly effective, stopping Excel from creating them in the first place is an even better strategy. You can adjust Excel's default settings to permanently prevent standard typing from being converted into curly quotes.

  1. Open Excel and click on the File tab in the ribbon.
  2. Select Options at the bottom of the left sidebar.
  3. In the Excel Options dialog, select Proofing.
  4. Click on the AutoCorrect Options... button.
  5. Navigate to the AutoFormat As You Type tab.
  6. Uncheck the box that says "Straight quotes" with “smart quotes”.
  7. Click OK to apply the changes.

By disabling this setting, Excel will honor your keystrokes exactly as you type them. Whenever you type a single or double quote, it will remain a clean, developer-friendly straight character.

Conclusion

Whether you work as a database administrator, software developer, data analyst, or sysadmin, Excel remains an invaluable utility tool for manipulating raw data. However, its consumer-facing word-processing assumptions can quickly cause syntax issues. By utilizing a nested SUBSTITUTE formula combined with UNICHAR codes, or leveraging a simple custom VBA function, you can confidently build data manipulation pipelines in Excel without worrying about hidden formatting bugs breaking your production code.

Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.