Menu

SUBSTITUTE and REPLACE in Excel: Swap Text in a Cell

=SUBSTITUTE(A2,"-","") removes every dash from A2: SUBSTITUTE swaps text by matching it. REPLACE swaps by position: =REPLACE(A2,1,3,"XYZ") overwrites the first 3 characters.

Every sheet on this page is live: change a number or a formula and it recalculates.

=SUBSTITUTE(A2,"-","") removes every dash from the text in A2: SUBSTITUTE finds the old text and puts the new text in its place, here empty text. =SUBSTITUTE(A2,"-",".") would put a dot in place of each dash instead.

Remove the dashes from phone numbers
B2
ABC
1PhoneDigits onlyWith dots
2555-201-33445552013344555.201.3344
3555-870-11225558701122555.870.1122
4555-433-90015554339001555.433.9001
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

The result is text, even when only digits are left. Add -- in front, =--SUBSTITUTE(A2,"-",""), when you need a number.

SUBSTITUTE vs REPLACE

=SUBSTITUTE(text, old_text, new_text, [instance_num])
=REPLACE(old_text, start_num, num_chars, new_text)

SUBSTITUTE looks for content: it does not care where old_text is. REPLACE does not look for anything: it counts characters and overwrites num_chars of them from start_num on.

Match by content or by position
B2
AB
1TextResult
2Report 2025 finalReport 2026 final
3Report 2025 finalReport 2026 final
4ID-0042SKU-0042
55551234555-1234
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.
  • B2 and B3 give the same result, but B3 only works because the year starts at character 8. If the text changes, SUBSTITUTE still finds it; REPLACE does not.
  • B4 swaps the first 2 characters, whatever they are, for SKU.
  • B5 uses a length of 0: nothing is removed, so REPLACE inserts the dash after the third character. That is the standard way to insert a character at a position.

Use SUBSTITUTE when you know the text, REPLACE when you know the position. For position-based edits, FIND can supply the position: =REPLACE(A2,FIND(" ",A2),1,"_") replaces the first space.

Replace only the second (nth) occurrence

The fourth argument of SUBSTITUTE picks which occurrence to change. Without it, all of them change:

The instance number
B3
AB
1PathResult
22026-03-15-final2026/03/15/final
32026-03/15-final
42026-03-15 final
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

B2 changes every dash. B3, with 2, changes only the second one and gives 2026-03/15-final; B4 puts a space in place of the third. An instance number larger than the count of matches changes nothing.

Rename the product line
B2
AB
1PlanNew name
2Basic monthly
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Your turn: In B2, replace Basic with Standard in the plan name in A2, using a formula.

Remove several different characters

SUBSTITUTE handles one old_text per call. For several, nest the calls: each one works on the result of the one inside it.

Clean a phone number
B2
AB
1PhoneDigits
2(555) 201-33445552013344
3(555) 870-11225558701122
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Read it from the inside out: remove (, then ), then -, then spaces. In Microsoft 365, =REGEXREPLACE(A2,"[^0-9]","") removes every character that is not a digit in one call. For extra spaces specifically, TRIM is the better tool, because it keeps one space between words.

Count occurrences of a character or word

SUBSTITUTE with empty text removes every occurrence, so the length lost is the number of characters removed. Divide by the length of the word to count words:

How many commas, how many times "red"
B2
ABC
1TextCommas"red" appears
2red, green, red, blue32
3Red, red, red22
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

C3 returns 2, not 3: SUBSTITUTE is case-sensitive, so Red is not removed. Use SUBSTITUTE(LOWER(A3),"red","") to count regardless of case.

Count the tags
B2
AB
1TagsCount
2excel,text,formulas,tips
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Your turn: The tags in A2 are separated by commas. In B2, count how many tags there are (one more than the number of commas).

Common mistake: SUBSTITUTE to change a number

SUBSTITUTE works on the text of a number, and the result is text. =SUBSTITUTE(A2,"0","") on 1050 gives 15 as text, and a format such as $1,050.00 is ignored because SUBSTITUTE reads the stored value, 1050. To change numbers, use arithmetic. To change text inside many cells at once, without formulas, Home > Find & Select > Replace (Ctrl+H; Control+H on a Mac) has a Match case option and replaces in place.

Frequently Asked Questions

What is the difference between SUBSTITUTE and REPLACE in Excel?

SUBSTITUTE finds text by its content: =SUBSTITUTE(A2,"old","new") changes every old. REPLACE works by position: =REPLACE(A2,5,3,"new") overwrites 3 characters starting at the 5th, whatever they are.

How do I remove a character from a cell in Excel?

Substitute it with empty text: =SUBSTITUTE(A2,"-","") removes every dash. For several characters, nest the calls: =SUBSTITUTE(SUBSTITUTE(A2,"(",""),")","").

How do I count how many times a character appears in a cell?

Compare the length before and after removing it: =LEN(A2)-LEN(SUBSTITUTE(A2,",","")) counts the commas in A2. For a word, divide by its length: =(LEN(A2)-LEN(SUBSTITUTE(A2,"red","")))/3.

Is SUBSTITUTE case-sensitive?

Yes. =SUBSTITUTE("Red red","red","blue") gives Red blue. To ignore case, lower the text first, =SUBSTITUTE(LOWER(A2),"red","blue"), or use Find and Replace (Ctrl+H), which ignores case by default.

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED