Remove line breaks in Excel
Put =SUBSTITUTE(A2,CHAR(10)," ") in an empty column: each line break in A2 becomes a space.
Which formula does which job?
CHAR(10) source is the line feed source, and SUBSTITUTE replaces every copy of it source.
- A2: Flat 4B⏎
MG Road⏎
Visakhapatnam - A3, a space before the break: Flat 4B ⏎
MG Road - A4, a no-break space: TotalNBSP amount
| Formula | Result |
|---|---|
=CLEAN(A2) | Flat 4BMG RoadVisakhapatnam |
=SUBSTITUTE(A2,CHAR(10)," ") | Flat 4B MG Road Visakhapatnam |
=SUBSTITUTE(A2,CHAR(10),", ") | Flat 4B, MG Road, Visakhapatnam |
=TRIM(SUBSTITUTE(A3,CHAR(10)," ")) | Flat 4B MG Road |
=TRIM(SUBSTITUTE(A4,CHAR(160)," ")) | Total amount |
What each formula did
=CLEAN(A2): the line breaks go, and the words on each side run together.=SUBSTITUTE(A2,CHAR(10)," "): a space stands where each line break was.=SUBSTITUTE(A2,CHAR(10),", "): the address on one line, part by part.=TRIM(SUBSTITUTE(A3,CHAR(10)," ")): TRIM folds the double space left where a space stood before the break.=TRIM(SUBSTITUTE(A4,CHAR(160)," ")): the no-break space becomes a plain one, which TRIM can then fold.
How do I apply it to a whole column?
Microsoft’s steps source, with a formula above in step 2:
- “Insert a new column (B) next to the original column (A) that needs cleaning.”
- “Add a formula that will transform the data at the top of the new column (B).”
- “Fill down the formula in the new column (B).”
- “Select the new column (B), copy it, and then paste as values into the new column (B).”
- “Remove the original column (A), which converts the new column from B to A.”
What else should I know?
What CLEAN removes and leaves
CLEAN removes the characters numbered 0 to 31 source. Among them are 9, the character tabulation, 10, the line feed (LF) and 13, the carriage return (CR) source, so CLEAN joins words that stood on separate lines; Microsoft’s own example takes CHAR(9) and CHAR(10) out of a cell source. It leaves the characters numbered 127, 129, 141, 143, 144 and 157 source, and the no-break space, number 160.
Why TRIM leaves a space
TRIM leaves single spaces between words and removes the rest source, but only the plain space, number 32; the no-break space, number 160, stays source. That is U+00A0, the no-break space source. Replace it with a plain space first, as in the last row of the table source.
If the break stays
Then the cell holds another character. Try CHAR(13), the carriage return, in place of CHAR(10), or use CLEAN. To see exactly what a text holds, paste it into Remove invisible characters.
Text outside a spreadsheet
Paste it into Remove line breaks: it keeps paragraphs and mends words split at a hyphen.