top of page

You are learning Functions and Formulas in MS Excel

How do I replace text with the SUBSTITUTE or REPLACE function?

Both SUBSTITUTE and REPLACE functions can be used to replace text in Excel, but they serve slightly different purposes:

SUBSTITUTE Function:

* Use SUBSTITUTE when you want to replace all occurrences of a specific text string with another text string within a cell.
* Syntax: `=SUBSTITUTE(text, old_text, new_text, [instance_num])`

- text: The cell reference containing the text you want to modify.
- old_text: The text string you want to replace.
- new_text: The text string you want to substitute in place of the old text.
- [instance_num] (optional): Specifies which occurrence of the old text you want to replace. If omitted, all occurrences will be replaced.

* Example:
- Formula: `=SUBSTITUTE(A1, "cat", "dog")` (assuming cell A1 contains text)
- If A1 contains "The brown cat jumps", the result will be "The brown dog jumps" (all "cat" instances are replaced).

REPLACE Function:

* Use REPLACE when you want to replace a specific number of characters at a specific location within a text string.
* Syntax: `=REPLACE(text, start_num, num_chars, new_text)`

- text: The cell reference containing the text you want to modify.
- start_num: The position of the first character you want to replace (starting from 1).
- num_chars: The number of characters you want to replace.
- new_text: The text string you want to substitute in place of the replaced characters.

* Example:
- Formula: `=REPLACE(A1, 6, 3, "dog")` (assuming cell A1 contains text)
- If A1 contains "The brown cat", the result will be "The brown dog" (characters 6-8, "cat", are replaced with "dog").

Choosing the Right Function:

* Use SUBSTITUTE for global replacements throughout the entire text string.
* Use REPLACE for targeted replacements at a specific location within the text string.

bottom of page