Remove Line Breaks From Cells
Strip newlines and tabs from text cells, replacing them with spaces and collapsing extra whitespace
What it does
A cell with Alt+Enter line breaks looks fine in Excel but breaks everything downstream. CSV exports turn each line break into a row split. Concatenations get weird gaps. Sort and filter get confused. The macro replaces every newline (CR, LF, CR+LF) and tab inside text cells with a single space, then collapses runs of spaces. Result: each cell becomes a single-line string, ready to export, sort, or feed into another system.
Real-world example
Picture a customer success manager at a B2B SaaS company building the weekly health-check report. The report pulls the customer notes column from a CRM export. Sales reps wrote the notes with Alt+Enter breaks for readability inside Excel: a heading line, a bullet of issues, a bullet of next steps. The CRM stores the line breaks. When she exports to CSV for the analytics tool, every Alt+Enter becomes a row split, and her 280 customer notes turn into 1,400 rows of jumbled fragments.
Her current method: open Find/Replace, expand options, type Ctrl+J in the find box (which inserts a literal newline character that the field shows as nothing), put a space in the replace box, click Replace All. Repeat for tab characters. About 90 seconds if she remembers the Ctrl+J trick, longer if she doesn't (which is most weeks because Ctrl+J is the kind of keyboard shortcut nobody uses except for this exact problem).
With this macro she selects the notes column, runs the tool, and 280 cells go from multi-line to single-line in 1 second. The popup confirms modified count. She exports to CSV. The analytics tool gets 280 rows like it should.
On a 280-row weekly customer-notes export, expect about 80 seconds saved per pass. Across a year that's about an hour back. The bigger win is consistent CSV exports without occasional silent corruption from forgotten line breaks.
How to use
First time? See How to run our tools for the 30-second setup.
- Select the range of cells with line breaks to remove.
- Press Alt + F8 (Windows) or Option + F8 (Mac), pick
RemoveLineBreaksFromCells, click Run. - The macro replaces every CR, LF, and tab with a single space, then collapses runs of spaces. The popup reports modified count.
FAQ
What characters does it replace?
Three line-break variants and the tab: carriage return (Chr 13), line feed (Chr 10), Windows-style CR+LF (Chr 13 + Chr 10), and tab (Chr 9). Each is replaced with a single space. After the replacements, runs of multiple spaces are collapsed to single spaces and leading/trailing whitespace is trimmed.
What if I want to keep the line breaks but replace them with something else (like a comma)?
Edit the .bas source: in NormalizeLineBreaks, change the " " replacement strings to "," or whatever you want. It's a 4-line edit. We may add a delimiter-picker option in a future version.
Does it skip formulas?
Yes. The macro only touches cells where HasFormula is False. So a formula returning a multi-line string isn't modified. To remove line breaks from formula results, freeze the formulas first with Convert Formulas to Values.
Will it touch cells that just have wrap text turned on but no actual line breaks?
No. "Wrap text" is a display setting; it doesn't insert real line break characters into the cell value. The macro looks for actual CR/LF/tab characters in the cell content. Cells with wrap-text turned on but no Alt+Enter are skipped.
Can I undo it?
Yes, Ctrl/Cmd + Z right after running undoes every modification. As always, work on a copy of your data first. The macro runs entirely offline. Your data never leaves your machine.
Did this tool work for you?
One click. We use this to fix tools that don't work and prioritize what to build next.
Related tools
Change Case to UPPERCASE or lowercase
Convert every text cell in your selection to UPPERCASE or lowercase in a single click
Clean Phone Numbers
Strip dashes, spaces, parens, and dots from a column of phone numbers so every entry is just digits
Clear All Comments
Delete every cell comment in your selection in one shot, with a confirmation prompt before deletion