Add line breaks in excel:
: Alt + enter
There are three ways to remove line breaks in excel:
Note: During the solution process, read other blogs and see the following methods:
1. I see that some people say "cancel automatic line wrapping" after selecting all. After saving, and then opening it, there are still line breaks.
2. ctrl+H, then press and hold alt to enter "10" or "0010", then replace, the test is invalid, maybe my operation is wrong
Solution:
M1:
- Find and replace directly, select the location you want to replace or select all (ctrl+a)
- Then press ctrl+h to open the replacement interface
- In the Replace Content window, type ctrl+j, it looks empty, but you can see a dot flashing.
- In the Replace with window, enter the content you want to replace, and enter nothing to delete it
- Then choose to replace all, or replace as needed
M2 and M3: No translation, looks a bit cumbersome
Original link: https://www.ablebits.com/office-addins-blog/2013/12/03/remove-carriage-returns-excel/
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).
Sub
RemoveCarriageReturns()
Dim
MyRange
As
Range
Application.ScreenUpdating =
False
Application.Calculation = xlCalculationManual
For
Each
MyRange
In
ActiveSheet.UsedRange
If
0 < InStr(MyRange, Chr(10))
Then
MyRange = Replace(MyRange, Chr(10),
""
)
End
If
Next
Application.ScreenUpdating =
True
Application.Calculation = xlCalculationAutomatic
End
Sub
|
If you don't know VBA really well, see How to insert and run VBA code in Excel