ShareYourGroupShareYourGroupExcel Formulas

Text functions

SUBSTITUTE and REPLACE functions in Excel

SUBSTITUTE swaps one piece of text for another wherever it appears; REPLACE swaps characters at a given position.

SUBSTITUTE is Find and Replace as a formula. It changes one piece of text into another, in every place it appears, and the result updates whenever the source cell changes. Use it to remove unwanted characters, to standardise spellings and to prepare text for conversion into numbers.

Syntax

=SUBSTITUTE(text, old_text, new_text, [instance_num])
=REPLACE(old_text, start_num, num_chars, new_text)
ArgumentWhat it is
textThe text to work on.
old_textFor SUBSTITUTE: the piece to find. Capital and small letters must match.
new_textWhat to put in its place. Use "" to delete.
instance_numWhich occurrence to change: 1 for the first, 2 for the second. If left out, all are changed.
start_num, num_charsFor REPLACE: where to start and how many characters to replace.

Examples

Each result below is what Excel itself showed for the formula on the sample sheet.

Sample sheet: Text as people really type it: stray spaces, mixed capitals, codes with dashes.
ABCD
1Full nameEmailCodeAmount as text
2  asha   verma asha.verma@example.comPB-10-12341,250
3RAVI KUMARravi@example.orgDL-08-0042300
4meena gillmeena.gill@example.comMH-12-9876 45.50 
5Kabir Khankabir@example.netRJ-14-000712 kg

SUBSTITUTE and REPLACE

The two names sound alike and work differently.

FunctionFinds what to change byUse it when
SUBSTITUTEthe text itselfyou know what the characters are: every dash, every "Ltd."
REPLACEpositionyou know where they are: characters 1 and 2, the last four

Most cleaning jobs want SUBSTITUTE.

Deleting characters

Give "" as the new text and the old text simply disappears. This is how to remove:

To remove several different characters, nest one SUBSTITUTE inside another, as above. Each one handles a single character.

Turning text into numbers

A value such as "1,250" or "12 kg" is text and will not add up. Strip the offending characters and then convert. Adding zero, multiplying by one or wrapping in VALUE all turn the cleaned text into a number, as the fourth and fifth examples show.

One occurrence only

The fourth argument picks out a single occurrence. =SUBSTITUTE(A2,"-"," ",2) changes only the second dash. This is the key to a classic trick for finding the last occurrence of a character: count how many there are with LEN, then substitute that numbered occurrence with a marker that appears nowhere else, and FIND the marker.

It is case sensitive

SUBSTITUTE treats capital and small letters as different. "ravi" does not match "RAVI", as the seventh example shows. To replace regardless of case, convert first: =SUBSTITUTE(LOWER(A2),"ravi","Ravi"), bearing in mind that the whole result is then in small letters.

Counting with SUBSTITUTE

Deleting a character and measuring how much shorter the text became counts its occurrences: =LEN(A2)-LEN(SUBSTITUTE(A2,",","")). See the LEN page.

REPLACE for masking and fixed layouts

REPLACE is right when the position is known. Hiding part of a number is the usual example: =REPLACE(A2,1,6,"XXXXXX") hides the first six characters of an account number. Giving 0 as the number of characters inserts text without removing any: =REPLACE(A2,3,0,"-") puts a dash after the second character.

The Find and Replace command

For a one-time change to the data itself, the Find and Replace box (Ctrl and H) is quicker than a formula. Use SUBSTITUTE when the cleaned result must keep following the source, or when you want to keep the original untouched.

Common mistakes

In Google Sheets

SUBSTITUTE and REPLACE are the same in Google Sheets. Sheets also has REGEXREPLACE for pattern-based replacement, which Excel 2021 does not have.

Related functions

Every result on this page was calculated in Microsoft Excel (version 16.0, build 20326) on 12 November 2026, not typed by hand.

This is an independent help site. It is not connected with or approved by Microsoft. Excel and Microsoft 365 are trademarks of Microsoft Corporation, named here only to say which program a formula is for. The people and figures in the sample sheets are made up.