Removing Carriage Returns in Excel Using the SUBSTITUTE Function

📅 Aug 14, 2026 📝 Sarah Miller

Cleaning imported database exports often wastes valuable analytical time when hidden carriage returns disrupt your spreadsheet formatting and lookup formulas. When consolidating administrative reports regarding standard funding sources, these erratic line breaks frequently corrupt your data structure.

Fortunately, leveraging a targeted SUBSTITUTE formula grants you complete automated control over your data presentation. Under the stipulation that Windows environments require CHAR(10) while Mac systems utilize CHAR(13), you can easily neutralize these breaks. For example, entering =SUBSTITUTE(A2, CHAR(10), " ") seamlessly replaces stubborn line breaks with clean, single spaces.

Below, we will break down the step-by-step process to apply this formula dynamically across your entire dataset.

Removing Carriage Returns in Excel Using the SUBSTITUTE Function

When working with data imported from external sources-such as SQL databases, CRM systems, web scrapes, or PDF conversions-you will often encounter stubborn formatting issues. One of the most common and frustrating culprits is the presence of unwanted line breaks. In Excel, these line breaks typically manifest as carriage returns (CR) or line feeds (LF).

Visually, these characters force text onto a new line within a single cell, making your spreadsheets look messy and disorganized. Operationally, they are even worse: they can break lookup formulas like VLOOKUP, XLOOKUP, or MATCH, because Excel treats "Data" and "Data[Line Break]" as two completely different strings.

Fortunately, Excel provides a highly reliable, formula-based solution to purge these invisible troublemakers. By combining the SUBSTITUTE function with Excel's native CHAR function, you can instantly clean thousands of rows of data. In this guide, we will explore exactly how to build and implement these formulas to sanitize your worksheets.

Understanding the Culprits: Carriage Returns vs. Line Feeds

Before writing the formulas, it helps to understand what we are actually trying to remove. Computers represent text characters using character sets (like ASCII). Non-printing layout control characters have their own numeric codes:

  • Line Feed (LF / CHAR(10)): This is the standard line break character used by Excel on Windows (created manually using Alt + Enter). It is also the standard line-ending character for Unix and macOS systems.
  • Carriage Return (CR / CHAR(13)): Historically used by classic Mac operating systems, this character is often paired with a Line Feed in Windows-based text files and database exports, forming a CRLF (Carriage Return + Line Feed) sequence.

When you copy data from web browsers or database GUIs, you often paste a mixture of these two hidden characters into your Excel sheets. Because they are non-printing, they can be incredibly difficult to spot unless you double-click inside a cell or look closely at the formula bar.

The Power of the SUBSTITUTE Function

The SUBSTITUTE function is designed to replace occurrences of a specific substring within a text string with a new substring. Its syntax is straightforward:

=SUBSTITUTE(text, old_text, new_text, [instance_num])
  • text: The reference to the cell containing the text you want to clean.
  • old_text: The character or string you want to search for and replace.
  • new_text: The text you want to insert in place of the old text. To remove a character entirely, you use an empty string ("").
  • instance_num (Optional): Specifies which occurrence of the old text to replace. If omitted, every occurrence is replaced (which is what we want).

Since we cannot type a literal carriage return or line feed directly into the old_text argument of a formula, we use the CHAR() function to generate them dynamically.

Formula 1: Removing Line Feeds (CHAR(10))

If your text has been formatted with standard Excel line breaks (Alt + Enter), you need to target CHAR(10). To replace these line breaks with a single space so that the text flows continuously, use this formula:

=SUBSTITUTE(A2, CHAR(10), " ")

If you want to remove the line break completely without leaving a space (for example, if a space already exists before or after the break), replace the space in the third argument with an empty string:

=SUBSTITUTE(A2, CHAR(10), "")

Formula 2: Removing Carriage Returns (CHAR(13))

If your data was imported from legacy software, external databases, or certain web forms, it might contain carriage returns (CHAR(13)). To replace them with spaces, write:

=SUBSTITUTE(A2, CHAR(13), " ")

Formula 3: The Universal Solution (Nested SUBSTITUTE)

Often, imported data contains both carriage returns and line feeds. If you only clean one, the other will still linger and cause formatting or lookup errors. To clean both characters simultaneously, you must nest one SUBSTITUTE function inside another.

The inner function removes the carriage returns, and the outer function takes that output and removes the line feeds:

=SUBSTITUTE(SUBSTITUTE(A2, CHAR(13), " "), CHAR(10), " ")

This is the safest "catch-all" formula for cleaning up raw data imports, ensuring that no matter which system generated the line breaks, your Excel sheet will standardise them into clean, single-line text.

Optimizing Your Cleaned Data with TRIM

When you replace carriage returns and line feeds with spaces, you may inadvertently create double spaces (e.g., if there was a space before the line break and you added another one). You might also end up with unwanted spaces at the very beginning or end of your text string.

To solve this, wrap your nested formula in Excel's TRIM function. TRIM automatically strips out all leading and trailing spaces, and reduces any consecutive spaces inside the string to a single space:

=TRIM(SUBSTITUTE(SUBSTITUTE(A2, CHAR(13), " "), CHAR(10), " "))

This nested combination is the gold standard for data cleaning. It guarantees your output is on a single line, is structurally consistent, and is perfectly prepped for lookup functions.

A Practical Example: Cleaning Address Data

Let's look at a common scenario. You import mailing addresses that look like this inside cell A2:

123 Innovation Way
Suite 400
Tech City, CA 94016

If you want to convert this multi-line address into a clean, comma-separated format on a single line, you can substitute the line breaks with a comma and a space (", "):

=TRIM(SUBSTITUTE(SUBSTITUTE(A2, CHAR(13), ", "), CHAR(10), ", "))

Note on double commas: If your text contains both CRLF sequences, replacing both independently with ", " might result in double commas (e.g., "Suite 400, , Tech City"). To prevent this, first strip out the carriage returns completely (using "") and then replace the remaining line feeds with your comma-space separator:

=TRIM(SUBSTITUTE(SUBSTITUTE(A2, CHAR(13), ""), CHAR(10), ", "))

This output will be perfectly formatted:

123 Innovation Way, Suite 400, Tech City, CA 94016

Why the CLEAN Function Isn't Always Enough

Excel does have a built-in function called CLEAN, which is designed to remove non-printable characters. You might wonder why we don't just use =CLEAN(A2).

While CLEAN successfully removes CHAR(10) and CHAR(13), it has one major drawback: it deletes them without adding a space separator. If your original text is "Hello[Line Break]World", the CLEAN function will return "HelloWorld". This merges words together and ruins your readability. Using SUBSTITUTE gives you precise control over what goes in place of the line break.

How to Replace the Formulas with Clean Values

Once you have applied your formulas and successfully cleaned your data, you will likely want to get rid of the formulas and keep only the cleaned text. Leaving formulas active can slow down large workbooks.

  1. Select the range of cells containing your SUBSTITUTE formulas.
  2. Press Ctrl + C to copy the cells.
  3. Right-click on the original data column (or a new destination column).
  4. Under Paste Options, select Paste as Values (represented by an icon with the numbers '123').
  5. You can now safely delete the helper column containing the formulas.

Summary Checklist

Goal Formula to Use
Remove standard in-cell line breaks =SUBSTITUTE(A2, CHAR(10), " ")
Remove database/legacy carriage returns =SUBSTITUTE(A2, CHAR(13), " ")
Clean both CR and LF with no double spaces =TRIM(SUBSTITUTE(SUBSTITUTE(A2, CHAR(13), " "), CHAR(10), " "))
Convert multi-line addresses to single-line comma-separated =TRIM(SUBSTITUTE(SUBSTITUTE(A2, CHAR(13), ""), CHAR(10), ", "))

By mastering the SUBSTITUTE and CHAR combination, you can quickly tackle dirty data imports, ensuring your spreadsheets remain professional, readable, and fully optimized for seamless reporting.

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.