What text formulas do
Text formulas work on the characters inside a cell. They can pull out part of a value, join several values into one, remove characters you don’t want, swap one piece of text for another, or change how a number or date looks as text. Most text formulas return text, even when the result looks like a number. That matters when you add, sort or look up the results later.
The main text functions at a glance
| Function | What it does | Example |
|---|---|---|
LEFT |
Takes characters from the start of a cell | =LEFT(A2,3) |
RIGHT |
Takes characters from the end of a cell | =RIGHT(A2,4) |
MID |
Takes characters from a position you choose | =MID(A2,5,3) |
LEN |
Counts characters | =LEN(A2) |
FIND and SEARCH |
Return the position of text inside a cell | =SEARCH("apple",A2) |
TRIM |
Removes extra spaces | =TRIM(A2) |
CLEAN |
Removes line breaks and other non-printing characters | =CLEAN(A2) |
SUBSTITUTE |
Replaces matching text with new text | =SUBSTITUTE(A2,"-","/") |
&, CONCAT and TEXTJOIN |
Join text from several cells | =TEXTJOIN(", ",TRUE,A2:A5) |
TEXT |
Formats a number or date as text | =TEXT(A2,"0.00") |
VALUE |
Converts text that looks like a number | =VALUE(A2) |
Pulling out part of a cell
LEFT takes characters from the start of a cell, RIGHT takes them from the end, and MID takes them from a position you choose. If a part code always starts with the same three letters, =LEFT(A2,3) returns them. When the piece you need moves around, you’ll usually combine these with FIND, which tells you where a space, dash or comma sits. Worked examples for names, codes and other pieces of a longer entry are in how to extract text from a cell in excel.
Finding where text sits
FIND and SEARCH both return the position of one piece of text inside another, as a number. FIND is case-sensitive and doesn’t accept wildcards. SEARCH ignores case and does accept them. Both return an error when the text isn’t there, so they’re often wrapped in IFERROR or tested with ISNUMBER. If you’re not sure which one to use, the comparison in find vs search in excel sets out the difference with examples.
Joining text from several cells
The & operator joins values directly. =A2&" "&B2 puts the text from two cells side by side with a space between them. CONCAT does the same for a range, and TEXTJOIN adds a separator between every value and can skip blank cells. TEXTJOIN needs Excel 2019 or Microsoft 365. Older guides use CONCATENATE, which still works but has been replaced by CONCAT. Joining dates and numbers takes an extra step, covered in how to combine text from cells in excel.
Cleaning up spaces and hidden characters
Extra spaces and invisible characters are a common reason a lookup misses or a count looks wrong. TRIM removes leading, trailing and doubled spaces. CLEAN removes line breaks and tabs. Neither removes every hidden character, so a non-breaking space from a web page may need its own SUBSTITUTE. Start with remove extra spaces in excel formula for the basics, and use remove non printing characters in excel when something is still hidden.
Swapping text for other text
SUBSTITUTE replaces matching text and can be limited to one occurrence. REPLACE works by position instead, swapping a set number of characters that start at a point you choose. Both are useful when a list has the same mistake or code to change. Copy-ready formulas for a substitute function in excel example are in their own walk-through.
Splitting text into pieces
Excel has Text to Columns on the Data tab. Microsoft 365 also has TEXTSPLIT, which spills the pieces into the cells beside it. How spilling works is explained in what are dynamic array formulas in excel. Google Sheets has a SPLIT function and a Split text to columns option, and split text by delimiter google sheets covers both. Spilled results need empty cells beside them, or Excel shows a spill error. The fix for that is in how to fix #spill error in excel.
Formatting numbers and dates as text
TEXT turns a number, date or time into text in the format you choose, such as =TEXT(A2,"$#,##0.00") for money or =TEXT(A2,"mm/dd/yyyy") for a date. It’s handy for labels like “Total: $1,250.00”, but the result can’t be used in calculations. The format codes and their pitfalls are in how to use text function in excel.
Turning text back into numbers
Numbers stored as text cause trouble. SUM skips them, so totals can come out low or zero. You can convert them with the Convert to Number option, with VALUE, or with a simple calculation such as --A2. The causes and steps are in how to convert text to number in excel. If a total is stuck on zero, why does sum show 0 in excel lists the usual reasons.
Errors you’ll run into
Three errors come up often with text:
#VALUE!usually means a function got text where it needed a number, or FIND couldn’t find the text. The fix is in how to fix #value error in excel.#NAME?usually means Excel can’t read something in the formula, such as a misspelled function name or text typed without quotation marks. Typos like this are covered in why does excel show #name error.- IFERROR keeps a sheet tidy, but it can also hide a real problem. When it helps, and when it doesn’t, is covered in how to hide errors in excel formulas.
Tips for working with text formulas
- Test a formula on a few rows before filling it down a whole column.
- Write formulas in a new column, and keep the original data until you’ve checked the results.
- For a long formula, step through each part with Evaluate Formula. The steps are in how to use evaluate formula in excel.
- Google Sheets has most of the same functions, with a few differences noted in each guide.