Sub topic 11
Multiple lines inside one cell
This chapter assumes you can select a cell, type into it, and commit an entry with Enter. It also assumes you know what the formula bar is and how to enter a formula. Here you will learn how to put more than one line of text in a single cell, why it sometimes fails, and how to fix it.
Why Enter does not work for line breaks
When you type in a cell and press Enter, Excel commits the entry and moves the active cell, usually down one row. Enter is the commit key, so it cannot also start a new line. Excel uses a different key combination for that.
A line break inside a cell is a character stored in the text. It is not formatting. Excel stores it as character code 10 (a line feed). Because it is a real character, it counts toward the cell's length, it can be searched for, and formulas can read it.
Inserting a line break while typing
While you are in edit mode, press Alt+Enter where you want the new line to start. On Mac, press Control+Option+Return. Newer Mac versions of Excel may also accept Command+Return.
- Select an empty cell, for example A1.
- Type
Ship to:. - Press Alt+Enter.
- Type
42 Harbor Road. - Press Alt+Enter again.
- Type
Springfield. - Press Enter to commit.
The cell now holds three lines. The row grows taller to show them if the row height is still automatic.
You can also add a line break in the middle of existing text. Double-click the cell or press F2 to enter edit mode. Click, or use the arrow keys, to place the cursor at the exact spot. Then press Alt+Enter. The text after the cursor moves to a new line.
The same technique in the formula bar
You can place the cursor in the formula bar and press Alt+Enter there. This is useful for long entries, because the formula bar can be expanded with the arrow at its right end or with Ctrl+Shift+U.
Wrap Text and line breaks are different things
Excel has a separate setting called Wrap Text, found on the Home tab in the Alignment group. It does not insert any characters. It only tells Excel to display text that is wider than the cell on several lines, breaking at the cell edge.
| Feature | Changes the stored text? | Where lines break | Changes if you resize the column? |
|---|---|---|---|
| Alt+Enter line break | Yes, adds character 10 | Exactly where you put it | No |
| Wrap Text | No, display only | At the cell edge | Yes |
Both can apply at once. When you press Alt+Enter, Excel normally turns on Wrap Text for that cell automatically. If you later see your multi-line text collapsed onto one line, the cause is almost always that Wrap Text was turned off. The line breaks are still stored, but Excel ignores them for display.
Row height
Rows have automatic height by default, so a cell with three lines should make the row taller. This stops working in these cases:
- You set the row height manually, by dragging the row border or by using Format > Row Height. The row then stays fixed, and extra lines are cut off.
- The cell is part of a merged range. Automatic row height does not adjust for merged cells.
- You typed the line break into a cell while Wrap Text was off and then turned it on later. The row may need to be adjusted.
To restore automatic height, select the row and double-click the bottom border of its row header. You can also use Home > Format > AutoFit Row Height.
Line breaks in formulas
You can build multi-line text with a formula by joining pieces with CHAR(10), the line feed character.
=A2&CHAR(10)&B2&CHAR(10)&C2If A2 holds a street, B2 a city, and C2 a postal code, this returns all three in one cell on separate lines. The result only appears on separate lines if Wrap Text is on for the cell. Excel does not turn it on for formula results, so you must set it yourself.
TEXTJOIN is shorter when you have many parts:
=TEXTJOIN(CHAR(10),TRUE,A2:C2)The first argument is the delimiter. The second, TRUE, tells Excel to skip empty cells so you do not get blank lines. TEXTJOIN is available in Excel 2019 and Microsoft 365, and not in earlier versions.
On Mac versions of Excel, CHAR(10) also works for line breaks in current releases.
Finding and removing line breaks
Line breaks are invisible, so removing them takes a specific method.
With Find and Replace
- Select the cells you want to change.
- Press Ctrl+H.
- Click in the Find what box and press Ctrl+J. The box appears empty, but a line feed is entered. You may see a small blinking dot.
- In Replace with, type a single space, or leave it empty to join the lines directly.
- Click Replace All.
Ctrl+J is the only way to type a line feed into the dialog. Pressing Alt+Enter there does nothing useful.
If you leave Replace with empty, the words at the break join together, for example RoadSpringfield. A space is usually safer.
With a formula
=SUBSTITUTE(A1,CHAR(10)," ")This returns the text from A1 with each line break replaced by a space. The original cell is unchanged. To keep only the result, copy the formula cells and use Paste Special > Values.
CLEAN(A1) also removes line breaks, along with other non-printing characters. It deletes them without leaving a space, so words can run together.
Counting lines
Because a line break is a character, you can count lines by counting line feeds and adding one:
=LEN(A1)-LEN(SUBSTITUTE(A1,CHAR(10),""))+1LEN returns the number of characters. Removing every line feed with SUBSTITUTE shortens the text by one character per break. The difference plus one is the number of lines. This formula returns 1 for an empty cell, so wrap it in an IF if you need 0 for blanks.
Common errors
- Pressing Enter and losing your place. If you press Enter by mistake, the entry is committed and the active cell moves. Double-click the cell or press F2, put the cursor where the break belongs, and press Alt+Enter.
- Alt+Enter does nothing on a cell that is not in edit mode. You must be typing in the cell or in the formula bar first.
- Breaks vanish when you paste. Text pasted into a cell from another program may arrive as several rows instead of one cell with line breaks. Edit the cell first, then paste into it, so Excel treats the text as one entry. Results vary by source program.
- A CSV export looks broken. In a CSV file, a cell containing line breaks is wrapped in quotation marks. Some programs that read the file do not understand this and split the cell into several rows. Remove the line breaks before export if the receiving program cannot handle them.
- Wrong character in a formula.
CHAR(13)is a carriage return, which Excel for Windows does not show as a line break. UseCHAR(10). - Sorting and filtering. Cells with line breaks sort and filter like any other text, but filter drop-down lists show the text on one line, so similar entries can look identical.
Related behavior to keep in mind
Line breaks fit with other topics in this tutorial. Entering one needs edit mode, as described in the chapter on editing. Clear and delete actions treat the break like any other character. A line break does not change the cell's data type, because the entry is still text. Excel stores the full text up to 32,767 characters per cell, although only the first 1,024 characters display in the cell itself on older versions. The formula bar shows the rest.
Exercise
Cell A1 contains an address typed with two Alt+Enter line breaks. After a colleague changes the cell format, A1 shows everything on one line, but the formula bar still shows three lines. What most likely happened, and how do you fix it? Then write a formula that returns the A1 text on a single line with spaces between the parts.
Show answer
Wrap Text was turned off for the cell. The line feed characters are still stored, which is why the formula bar still shows three lines, but Excel does not display them in the cell. Fix it by selecting A1 and turning on Wrap Text on the Home tab, then autofit the row height if needed. The single-line formula is =SUBSTITUTE(A1,CHAR(10)," ").
Exercise
You want B2 to show the contents of A2, B2's neighbor C2, and D2 on separate lines, skipping any empty cells. Which formula do you use, and what must you do afterward so the lines appear?
Show answer
Use =TEXTJOIN(CHAR(10),TRUE,A2,C2,D2). The TRUE argument skips empty cells. Afterward, turn on Wrap Text for the cell that holds the formula, because Excel does not do it automatically for formula results.