In this tip you'll find 3 ways to remove carriage returns from Excel cells. You'll also learn how to replace line breaks with other symbols. All solutions work for Excel 365, 2021, 2019, and lower versions.
There can be different reasons for line breaks occurring in your text. Usually, carriage returns appear when you copy text from a webpage, get a workbook that already contains line breaks from a customer, or you add them yourself using Alt+Enter.
In any case, what you want to do now is delete carriage returns since they don't let you find a phrase and make column contents look disorganized when you turn on the wrap text option.
Please note that initially the terms "Carriage return" and "Line feed" were used in a typewriter and meant 2 different actions, you can find more at Wiki.
Computers and text processing software were created taking into consideration the typewriter specificities. That's why two different non-printable symbols are used now to indicate line break: "Carriage return" (CR, ASCII code 13) and "Line Feed" (LF, ASCII code 10). Windows uses 2 symbols one by one: CR+LF, and LF for *NIX systems. Be careful: in Excel you can find both variants. If you import data from a .txt or .csv file, you are more likely to find Carriage Return + Line Feed. When you break a line using Alt+Enter , Excel inserts Line Feed only.
In case you get .csv files from a person who uses Linux, Unix, etc., you'll find only Line Feeds again.
All these 3 ways are really quick. Feel free to pick the one that suites you best:
Tip. For your are looking for a solution to the opposite task, then read how to quickly add a line break in Excel cell.
Remove Carriage Returns manually
Pros: the fastest way.
Cons: no any additional features :(.
Please find the steps for eliminating line breaks using Find and Replace:
- Select all cells where you want to remove or replace carriage returns.
- Press Ctrl+H to open the Find & Replace dialog box.
- In the Find What field enter Ctrl+J. It will look empty, but you will see a tiny dot.
- In the Replace With field, enter any value to replace carriage returns. Usually, it is space to avoid 2 words join accidentally. If all you need is deleting the line breaks, leave the "Replace With" field empty.
- Press the Replace All button and enjoy the result!
Delete line breaks using Excel formulas
Pros: you can use a formula chain / nested formulas for complex cell text processing. For example, it is possible to remove carriage returns and then eliminate excess leading and trailing spaces and those between words.
Or you may need to delete carriage returns to use your text as an argument of another function without changing the original cells. For example, if you want to be able to use the result as an argument of the function =lookup ().
Cons: you'll need to create a helper column and follow many extra steps.
- Add the helper column to the end of your data. You can name it "1 line".
- In the first cell of the helper column (C2), enter the formula to remove / replace line breaks. Here you can see several helpful formulas for different occasions:
- Handle both Windows and UNIX carriage return/ line feeds combinations.
=SUBSTITUTE(SUBSTITUTE(B2,CHAR(13),""),CHAR(10),"") - The next formula will help you replace line break with any other symbol (comma+space). In this case lines will not join and extra spaces will not appear.
=TRIM(SUBSTITUTE(SUBSTITUTE(B2,CHAR(13),""),CHAR(10),", ") - If you want to remove all nonprintable characters from text, including line breaks:
=CLEAN(B2)
- Handle both Windows and UNIX carriage return/ line feeds combinations.
- Copy the formula across the other cells in the column.
- Optionally, you can replace the original column with the one where the line breaks were removed:
- Select all cells in column C and press Ctrl + C to copy the data to clipboard.
- Now pick the cell B2 and press the Shift + F10 shortcut. Then just press V.
- Remove the helper column.
VBA macro to get rid of line breaks
Pros: Being created once, can be reused in any workbook.
Cons: you need to have the basic knowledge of VBA.
The VBA macro from the example below deletes carriage returns from all cells in the currently opened worksheet (active worksheet).
If you don't know VBA really well, see How to insert and run VBA code in Excel
Remove carriage returns with Text Toolkit
If you are a lucky user of our Ultimate Suite for Excel, then you do not need to waste time on any of the above manipulations. All it takes is these 3 quick steps:
- Select one or more cells where you want to delete line breaks.
- On your Excel ribbon, go to the Ablebits Data tab > Text group, and click the Convert button.
- On the Convert Text pane, select the Convert line break to radio button, type the "replacement" character in the box, and click Convert.
In our example, we are replacing each line break with a space, so you put the mouse cursor in the box and press the Enter key:
As the result, you will have a neatly organized table with one-line addresses:
If you are curious to try this and 60 more time-saving tools for Excel, you are welcome to download a trial version of our Ultimate Suite. You will be amazed to discover a-few-clicks solutions for the most challenging and tedious tasks in Excel!
Video: How to remove line breaks in Excel
158 comments
Hi,
You have no idea in how much you helped me with this information.
Thank you very much man.
God bless you !
I'm trying to use the manual replacement with Ctrl+J, the dot shows up, but it says it can't find anything when clearly I see the cells have carriage returns (created by doing alt+enter) within the cell.
If you want to do this with a Mac, you have to use Google sheets as an intermediary platform.
Copy the word document table as is and paste in Google sheets. It will paste it as it is meant to be, then download the file in XLSX format.
This should solve the problem.
I just wanted this and got it. So simple and easy. Thanks.
Thanks. Great tip. Very easy with the Ctrl+H Ctrl+J
Great ! the trick for manual reaplacement of CR+LF,
tnks
On Excell office 2013 (my current version) if the above formula not working, you only want to change to : =SUBSTITUTE(SUBSTITUTE(B2;CHAR(13);"");CHAR(10);"")
(my formula is only changing the comas TS formula)
thank U
Is there a way to do this from unix command line?
The manual method is just what I needed, when I needed it. The line returns were making pasting content into a SharePoint table quite a problem, and manually removing them was not practical. CTRL+J = line return? Who knew? (well, yeah, you did) Thanks!
Thanks!
Excellent! thanks a lot. It saved me a ton of work for my next spreadsheet
Thanks .. for great help..
Hi, this blog is awesome.
How can I remove lines within each cell (multiple lines in one cell with line breaks) that are not starting with a numeric character?
Thanks and best,
Jack
I was looking for a way to deal with line breaks after scraping some text from the web and was able to adapt the code you provided here to my own.
Thank you very much! I was on the verge of pulling my hair out!
The VBA macro from the example below deletes carriage returns from all cells in the currently opened worksheet (active worksheet).
Your code actually removes (Chr 10) Line Feed char i.e LF not CR which is returned by Chr(13)
Thanks
Hi,
You are doing amazing work!!
I need your help on below requirement.
I have an excel sheet with datas:
Col A-Box with size 1, Col A-Boxsize-1 % full, col-3 last time items stored in the box, col 4-Box size 2 which is twice in capacity as box 1.
Using VBA macro or Excel formula I want to do below;
1. sort % column from higher to lower and create another Box size 1.
2. sort date column from lower to higher
3. combine boxes with size 1 such that total % should not exceed 180% and map it to box size2(any box as box is empty)
e.g A1+A6 has perfect 180%
A1(92%, 2017)and A6(88%, 2013) are having perfect % sum but dates are different.
A1(92%, 2017 and A3(82%, 2017) are having sum very close to 180 i.e. 174% and dates are also same 2017.
It can be multiple 2 or boxes to make perfect sum
4. We have utilize sizes at max
5. Also, boxes of same same dates(year) should go to target box
6. All the reamaing can be be put into one box(% should not exceed)
Input file:
Box size1 %Full last date item stored Box size2
A1 92% 4/18/2017 B1
A2 77% 4/18/2017 B2
A3 82% 4/18/2017 B3
A4 91% 2/11/2013 B4
A5 91% 2/10/2013 B5
A6 88% 2/22/2013 B6
A7 92% 2/22/2013 B7
A8 10% 2/22/2013 B8
A9 92% 6/6/2013 B9
A10 22% 7/8/2013 B10
A11 2% 4/18/2017 B11
A12 12% 4/19/2017 B12
A13 96% 4/19/2017 B13
A14 90% 2/11/2013 B14
A15 92% 12/28/2012 B15
A16 92% 6/6/2013 B16
A17 99% 2/22/2013 B17
A18 97% 2/22/2013 B18
A19 4% 2/22/2013 B19
A20 5% 7/8/2013 B20
Output file
Box size1 %Full last date item stored Box size2
A1 92% 4/18/2017 B1
A3 82% 4/18/2017 B1
A6 88% 2/22/2013 B2
A7 92% 2/22/2013 B2
A2 77% 4/18/2017 B3
A18 97% 2/22/2013 B3
A20 6% 7/8/2013 B3
.
.
.
so on
Can you please help me on this? Thanks!
I am using Mac and the CTRL + J do not function in my laptop. Can anyone help me?
Try Command instead of CTRL
I have a numbers in cell like
12332488,
56777777,
45654677,
like this more then 10,000.
i want these numbers should display in the same cell with each line 4 numbers. please let me know if there is any solution