Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING HTML & CSS BASH RUST TOOLS

Excel Tutorial

Excel HOME Excel Introduction Excel Get Started Excel Overview Excel Syntax Excel Ranges Excel Fill Excel Move Cells Excel Add Cells Excel Delete Cells Excel Undo Redo Excel Formulas Excel Relative Reference Excel Absolute Reference Excel Arithmetic Operators Excel Parentheses Excel Functions

Excel Formatting

Excel Formatting Excel Format Painter Excel Format Colors Excel Format Fonts Excel Format Borders Excel Format Numbers Excel Format Grids Excel Format Settings

Excel Data Analysis

Excel Sort Excel Filter Excel Tables Excel Conditional Format Excel Highlight Cell Rules Excel Top Bottom Rules Excel Data Bars Excel Color Scales Excel Icon Sets Excel Manage Rules (CF) Excel Charts

Excel PivotTables

Excel PivotTable Intro Excel Create PivotTable Excel PivotTable Values Excel PivotTable Filter Excel PivotTable Group Excel Calculated Field Excel PivotChart

Excel Case

Case: Poke Mart Case: Poke Mart, Styling

Excel Functions

AND AVERAGE AVERAGEIF AVERAGEIFS CONCAT COUNT COUNTA COUNTBLANK COUNTIF COUNTIFS DATEDIF FILTER HLOOKUP IF IFERROR IFS INDEX INDEX MATCH LEFT LEN LOWER MATCH MAX MEDIAN MID MIN MODE NETWORKDAYS NPV OR PROPER RAND RIGHT ROUND SORT STDEV.P STDEV.S SUBSTITUTE SUM SUMIF SUMIFS SUMPRODUCT TEXTJOIN TODAY TRIM UNIQUE UPPER VLOOKUP XLOOKUP XOR

Excel How To

Convert Time to Seconds Difference Between Times NPV (Net Present Value) Remove Duplicates

Excel Cert

Excel Certificate

Excel Examples

Excel Exercises Excel Syllabus Excel Study Plan Excel Training

Excel References

Excel Keyboard Shortcuts


Excel SUBSTITUTE Function


Share

SUBSTITUTE Function

The SUBSTITUTE function is a premade function in Excel, which replaces text in a cell with new text.

It can replace every occurrence of the text, or only one of them.

It is typed =SUBSTITUTE and has the following parts:

=SUBSTITUTE(text, old_text, new_text, [instance_num])

Note: The different parts of the function are separated by a symbol, like comma , or semicolon ;

The symbol depends on your Language Settings.

Text: The text to change. This is usually a cell.

Old_text: The text to replace. Type it inside double quotes, like "MEDS".

New_text: The text to put in its place, also inside double quotes.

Instance_num: Optional. Which occurrence of old_text to replace, like 2 for the second one. If you leave it out, every occurrence is replaced.

Note: SUBSTITUTE is case-sensitive. "ball" does not match Ball. You can read more about this further down the page.

How to use the SUBSTITUTE function:

  1. Select a cell (C2)
  2. Type =SUBSTITUTE
  3. Double click the SUBSTITUTE command
  4. Select the cell with the text (B2)
  5. Type (,)
  6. Type the text to replace, inside double quotes ("MEDS")
  7. Type (,)
  8. Type the new text, inside double quotes ("HEAL")
  9. Hit enter

Let's have a look at an example!

These are the products in the Poke Mart shop, with their item codes. Copy them and paste them into cell A1 to follow along:

Example data

AB
1ProductItem Code
2Poke BallPKB-0200-BALL
3Great BallGRB-0600-BALL
4Ultra BallULB-1200-BALL
5PotionPOT-0300-MEDS
6Super PotionSPT-0700-MEDS
7Hyper PotionHPT-1200-MEDS
8ReviveREV-1500-MEDS
9AntidoteANT-0100-STAT
10Paralyze HealPRH-0200-STAT
11AwakeningAWK-0250-STAT

The last part of each item code is the category: BALL, MEDS or STAT. The shop has decided to rename the MEDS category to HEAL.

Type the label New Code in C1.

Use the SUBSTITUTE function to make the new codes:

ABC
1ProductItem CodeNew Code
2Poke BallPKB-0200-BALLPKB-0200-BALL
3Great BallGRB-0600-BALLGRB-0600-BALL
4Ultra BallULB-1200-BALLULB-1200-BALL
5PotionPOT-0300-MEDSPOT-0300-HEAL
6Super PotionSPT-0700-MEDSSPT-0700-HEAL
7Hyper PotionHPT-1200-MEDSHPT-1200-HEAL
8ReviveREV-1500-MEDSREV-1500-HEAL
9AntidoteANT-0100-STATANT-0100-STAT
10Paralyze HealPRH-0200-STATPRH-0200-STAT
11AwakeningAWK-0250-STATAWK-0250-STAT
=SUBSTITUTE(B2, "MEDS", "HEAL")

The function is repeated with the filling function for each row, down to C11.

The four codes with MEDS now have HEAL instead, like POT-0300-HEAL. The other codes do not contain MEDS, so SUBSTITUTE returns them unchanged.



Replace One Occurrence or All

Each item code has two dashes. Without instance_num, SUBSTITUTE replaces both of them. With instance_num, it replaces only the one you choose.

Type PKB-0200-BALL in A2, A3 and A4 of a new sheet, and replace the dashes with spaces:

AB
1CodeResult
2PKB-0200-BALLPKB 0200 BALL
3PKB-0200-BALLPKB 0200-BALL
4PKB-0200-BALLPKB-0200 BALL

The formulas in B2, B3 and B4:

=SUBSTITUTE(A2, "-", " ")
=SUBSTITUTE(A3, "-", " ", 1)
=SUBSTITUTE(A4, "-", " ", 2)

B2 has no instance_num, so both dashes are replaced.

B3 has instance_num 1, so only the first dash is replaced.

B4 has instance_num 2, so only the second dash is replaced.


Remove Characters

To remove a character, replace it with an empty text. An empty text is two double quotes with nothing between them: ""

Go back to the Poke Mart sheet. Type the label No Dashes in D1, and remove the dashes from the item codes. Fill the formula down to D11:

BD
1Item CodeNo Dashes
2PKB-0200-BALLPKB0200BALL
3GRB-0600-BALLGRB0600BALL
4ULB-1200-BALLULB1200BALL
5POT-0300-MEDSPOT0300MEDS
6SPT-0700-MEDSSPT0700MEDS
7HPT-1200-MEDSHPT1200MEDS
8REV-1500-MEDSREV1500MEDS
9ANT-0100-STATANT0100STAT
10PRH-0200-STATPRH0200STAT
11AWK-0250-STATAWK0250STAT
=SUBSTITUTE(B2, "-", "")

Every dash is replaced with nothing, so PKB-0200-BALL becomes PKB0200BALL.

The same works for spaces. =SUBSTITUTE(A2, " ", "") changes Poke Ball into PokeBall.


SUBSTITUTE is Case-Sensitive

SUBSTITUTE only replaces text that has exactly the same uppercase and lowercase letters as old_text.

Type Poke Ball in A2 and A3 of a new sheet, and try to replace Ball with Orb:

AB
1ProductResult
2Poke BallPoke Ball
3Poke BallPoke Orb

The formulas in B2 and B3:

=SUBSTITUTE(A2, "ball", "Orb")
=SUBSTITUTE(A3, "Ball", "Orb")

B2 looks for ball with a lowercase b. There is none in Poke Ball, so nothing is replaced, and there is no error either.

B3 looks for Ball with an uppercase B, and finds it.

Note: Excel's Find and Replace tool (Ctrl+H) works differently. By default, it does not care about uppercase and lowercase. It only matches the case if you check Match case in its options.

If a replacement seems to do nothing, check the uppercase and lowercase letters in old_text first. You can use UPPER, LOWER or PROPER to make the letter case the same before you replace.


Related Functions

To remove extra spaces, use TRIM. To count how many times a character appears, combine SUBSTITUTE with LEN.


Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.