Cellwise Try it free

Excel guide · 3 min read

How to replace text in Excel with a formula

Quick answerUse =SUBSTITUTE(A2,"old","new"). It swaps every match of "old" for "new" and leaves the original cell unchanged. Add a fourth argument to replace only one match, for example =SUBSTITUTE(A2,".","-",2) changes only the second dot. To replace text in the cells themselves, press Ctrl+H for Find and Replace.

Sample data

Every result on this page was calculated from this sheet by the same spreadsheet engine the Cellwise app uses.

ABCD
1ProductPhoneAddressCode
2Trail Runner 2025 (2025 model)555.201.441714 Elm St, Apt 3OLD-4471
3Desk Lamp 2025555.380.99219 Oak Ave, Unit 12OLD-4472
4Water Bottle Mini(555) 614 2290221 Pine RdOLD-4480

Download this sheet as an Excel practice file (.xlsx)

Replace every match with SUBSTITUTE

SUBSTITUTE has three required arguments: the text, the text to find, and what to put in its place. It replaces every match it finds, and it returns a new value in the formula cell. The original stays as it was.

Here dotted phone numbers become dashed ones. Fill the formula down to fix the whole column.

=SUBSTITUTE(B2,".","-")

Result: 555-201-4417

Returns "555-201-4417".

Replace only the first, second or nth match

The optional fourth argument, instance_num, tells SUBSTITUTE which match to change. The product name below mentions 2025 twice, but only the first one is the product name. Changing just instance 1 keeps the note in brackets intact.

There is no built-in way to say "the last match". Count the matches with LEN(A2)-LEN(SUBSTITUTE(A2,"x","")) and pass that number as instance_num.

=SUBSTITUTE(A2,"2025","2026",1)

Result: Trail Runner 2026 (2025 model)

Returns "Trail Runner 2026 (2025 model)".

Replace several different things at once

SUBSTITUTE handles one find-and-replace pair. For more, nest them: the inner SUBSTITUTE runs first and the outer one works on its result. Here "St" and "Apt" are expanded in one formula.

Nesting gets hard to read after four or five levels. For long lists of replacements, keep the pairs in a two-column table and use Find and Replace, or in Excel 365 a LET or LAMBDA formula.

=SUBSTITUTE(SUBSTITUTE(C2,"St,","Street,"),"Apt","Apartment")

Result: 14 Elm Street, Apartment 3

Returns "14 Elm Street, Apartment 3".

Change a prefix (and why the comma matters)

Include enough of the surrounding text to make the match unique. Replacing "OLD-" rather than "OLD" means a code like OLD-4471 changes, but a product called "Old Oak Table" would not be touched, partly because SUBSTITUTE is case-sensitive and partly because the dash must be there too.

The same idea is why the address example searches for "St," with the comma: a bare "St" would also change the "St" in a street name like "Stone Rd".

=SUBSTITUTE(D3,"OLD-","SKU-")

Result: SKU-4472

Returns "SKU-4472".

REPLACE: change text by position

Excel also has a REPLACE function. It does not search for anything. You tell it where to start and how many characters to overwrite: =REPLACE(D2,1,3,"NEW") replaces the first 3 characters and returns "NEW-4471". Use it for fixed-layout codes where the position matters but the content varies.

Use SUBSTITUTE when you know what the text says, and REPLACE when you know where it is.

Replace in the cells themselves: Find and Replace

If you want the cells changed, not a new column, use Find and Replace. It is not case-sensitive by default, and it supports wildcards: * matches any run of characters and ? matches one. To find a real asterisk or question mark, put a tilde in front: ~*.

  1. Select the cells to change (or one cell to search the whole sheet).
  2. Press Ctrl+H, or go to Home > Find & Select > Replace.
  3. Type the text in Find what and the new text in Replace with.
  4. Click Options to set Match case or Match entire cell contents if needed.
  5. Click Replace All, then check the count Excel reports.

Common mistakes

Expecting SUBSTITUTE to ignore case

SUBSTITUTE("Old Oak","old","new") changes nothing, because "old" is not "Old". Match the exact case, or use Find and Replace, which ignores case unless you tick Match case.

Numbers turn into text

SUBSTITUTE always returns text. If the result should be a number, such as a price with the commas removed, wrap it in VALUE or put -- in front.

Replacing a short string that appears inside other words

Replacing "St" also hits "Stone" and "Station". Include a space, comma or other neighbour in the search text so it only matches what you mean.

Replace All with a stray wildcard

In Find and Replace, "*" alone matches every cell and Replace All overwrites them all. Undo with Ctrl+Z, then search for ~* to mean a literal asterisk.

FAQ

What is the difference between SUBSTITUTE and REPLACE in Excel?

SUBSTITUTE finds text by what it says and swaps it. REPLACE ignores the content and overwrites a number of characters at a position you give it. Use SUBSTITUTE for words and symbols, REPLACE for fixed positions in codes.

How do I replace text with nothing in Excel?

Use an empty string as the new text: =SUBSTITUTE(A2,"-",""). It removes every dash. In Find and Replace, leave Replace with empty.

Can SUBSTITUTE replace multiple values?

Not in one call. Nest one SUBSTITUTE inside another for each pair, such as =SUBSTITUTE(SUBSTITUTE(A2,"a","b"),"c","d").

How do I replace a line break in Excel?

Use =SUBSTITUTE(A2,CHAR(10),", "). In Find and Replace, click in Find what and press Ctrl+J to enter a line break.

Functions used

Related guides

Updated