How to Replace Line Breaks with Commas in Excel

📅 Apr 02, 2026 📝 Sarah Miller

Manually cleaning awkward line breaks within Excel cells is a tedious chore that disrupts efficient data analysis. This formatting issue frequently arises when professionals export compiled directories of standard funding sources into spreadsheets for review. Successfully converting these breaks into commas grants instant compatibility and readability across your reports. However, as an educational stipulation, one must note that Windows and Mac systems utilize different character codes (like CHAR(10) versus CHAR(13)) for line breaks, which is particularly common in data from federal grant databases. Below, we provide the precise formula to automate this transition seamlessly.

How to Replace Line Breaks with Commas in Excel

When working with data in Excel, you often encounter cells containing multi-line text. While line breaks (created by pressing Alt + Enter) are great for making data readable within a single sheet, they can quickly become a nightmare when you need to export the data, use it in formulas, or prepare it for import into other software databases. In these scenarios, converting those vertical line breaks into a clean, comma-separated list is the most common solution.

In this comprehensive guide, we will explore the best Excel formulas to replace line breaks with commas, address compatibility across different operating systems (Windows vs. Mac), solve common edge cases (like handling consecutive line breaks), and introduce alternative non-formula methods like Find & Replace and Power Query.


Understanding the Core Concept: ASCII Characters

Before writing the formula, it helps to understand how Excel recognizes a line break. Excel does not see a "blank space" or "enter key"; instead, it reads invisible computer characters known as ASCII control codes.

  • Line Feed (LF) / CHAR(10): This is the standard line break character used in Windows Excel.
  • Carriage Return (CR) / CHAR(13): This is historically used by Mac operating systems and occasionally appears in data copied from external web systems or text files.

To manipulate these invisible characters, we must pair Excel's SUBSTITUTE function with the CHAR function.


Method 1: The Standard SUBSTITUTE Formula (Windows)

For the vast majority of Windows users, replacing a line break with a comma and a space is incredibly straightforward. You will use the SUBSTITUTE function to hunt down CHAR(10) and swap it out.

The Formula:

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

How It Works:

  • A2: The cell containing the multi-line text you want to clean.
  • CHAR(10): The search target, which represents the line break (Line Feed).
  • ", ": The replacement string. We include a space after the comma to ensure the resulting text is easy to read (e.g., "Item 1, Item 2" instead of "Item 1,Item 2").

Step-by-Step Implementation:

  1. Click on an empty cell next to your source data (e.g., B2).
  2. Type or paste the formula: =SUBSTITUTE(A2, CHAR(10), ", ").
  3. Press Enter.
  4. Hover your mouse over the bottom-right corner of the formula cell until the fill handle (a small plus sign) appears, then double-click or drag it down to apply the formula to the rest of your column.

Method 2: The Mac Excel and Cross-Platform Formula

If you are working on a Mac, or if your data was imported from an external database or TXT file, the line breaks might be encoded as Carriage Returns (CHAR(13)) or a combination of Carriage Returns and Line Feeds (CRLF / CHAR(13) & CHAR(10)).

To ensure your formula works universally across Windows, Mac, and web formats, you can nest multiple SUBSTITUTE functions together:

The Universal Formula:

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

How It Works:

This nested formula acts as a two-step filter. First, the inner SUBSTITUTE finds any Carriage Returns (CHAR(13)) and replaces them with commas. Then, the outer SUBSTITUTE scans that result, finds any remaining Line Feeds (CHAR(10)), and converts those to commas as well. This prevents your formula from failing when encountering mixed line-ending formats.


Method 3: Handling Multiple Consecutive Line Breaks (Modern Excel 365)

A common formatting issue occurs when users press Alt + Enter multiple times in a row to create visual gaps between paragraphs. If you use the basic SUBSTITUTE formula on this kind of data, you will end up with messy results, such as multiple consecutive commas (e.g., Item 1, , , Item 2).

If you are using Microsoft 365 or Excel 2021, you can combine TEXTJOIN and TEXTSPLIT to elegantly solve this issue. This combination splits the text into pieces by the line break, and then joins them back together while automatically ignoring empty spaces.

The Formula:

=TEXTJOIN(", ", TRUE, TEXTSPLIT(A2, CHAR(10)))

How It Works:

  • TEXTSPLIT(A2, CHAR(10)): Splits the text in cell A2 into an array of separate items, using the line break as the dividing point.
  • TEXTJOIN(", ", TRUE, ...): Merges those split items back into a single string. The first argument (", ") defines the comma-separator. The second argument (TRUE) is the magic parameter-it tells Excel to entirely skip any empty values generated by consecutive line breaks.

Method 4: The Keyboard Shortcut Trick (No Formulas Required)

If you don't want to create helper columns with formulas and simply want to permanently modify the existing data in-place, Excel's Find and Replace feature is your best friend. However, you cannot simply type "Enter" into the Find box. Instead, you must use a special keyboard shortcut.

Step-by-Step Instructions:

  1. Select the column or range of cells containing the line breaks you want to replace.
  2. Press Ctrl + H on your keyboard to open the Find and Replace dialog box.
  3. Click into the Find what: input box.
  4. Press Ctrl + J. (Note: You won't see any letters appear, but you might notice a tiny, blinking dot or a slight shift in the cursor. This shortcut inserts the invisible Line Feed character).
  5. Click into the Replace with: input box and type a comma followed by a space (, ).
  6. Click Replace All.

Excel will quickly run through your selected data, swap out all line breaks, and display a confirmation message showing how many replacements were made.


Method 5: Cleaning Line Breaks Globally with Power Query

For large datasets, automated reports, or data imports that you refresh on a regular basis, Power Query is the most robust tool for the job. It allows you to build a repeatable data-cleaning pipeline.

Step-by-Step Instructions:

  1. Select your data range, go to the Data tab on the Excel ribbon, and click From Table/Range to import your data into the Power Query Editor.
  2. Right-click the header of the column containing the line breaks.
  3. Select Replace Values... from the context menu.
  4. In the "Value To Find" input box, do not type anything. Instead, look at the bottom-left of the dialog box and check the option for Replace using special characters.
  5. Click the Insert special character dropdown menu and select Line feed (which inserts #(lf)).
  6. In the "Replace With" box, type your comma and a space (, ).
  7. Click OK.
  8. Click Close & Load from the Home tab to send your cleaned, comma-separated data back to a new worksheet in Excel.

Choosing the Right Tool for Your Task

With so many methods available, which one should you choose? Refer to the comparison table below to determine the best approach for your specific scenario:

Method Dynamic/Static Best For... Difficulty
SUBSTITUTE Formula Dynamic (updates instantly) Standard everyday sheets, quickly cleaning individual cells dynamically. Easy
TEXTJOIN & TEXTSPLIT Dynamic (updates instantly) Handling messy, inconsistent spacing and multiple consecutive line breaks. Intermediate
Ctrl + J (Find & Replace) Static (permanent change) One-off cleanups when you don't want to create extra "helper" columns. Easy
Power Query Dynamic (updates on refresh) Recurring reports, large system exports, and automated data pipelines. Advanced

Pro Tip: Reverting the Process (Commas back to Line Breaks)

If you ever need to reverse this operation-converting a comma-separated list back into a stacked, multi-line format-you can simply flip the formula arguments around. Here is the formula to convert commas back into clean line breaks:

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

Note: If you use this formula, ensure that "Wrap Text" is enabled on your destination cells (Home tab > Wrap Text), otherwise Excel will display the line breaks as ordinary blank spaces.


Summary

Removing messy line breaks and converting them to commas doesn't have to involve manual, tedious editing. By mastering the =SUBSTITUTE(A2, CHAR(10), ", ") formula, utilizing the Ctrl + J keyboard shortcut, or adopting modern tools like TEXTSPLIT and Power Query, you can transform cluttered spreadsheets into clean, structured data in seconds.

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.