wmfexcel


Home | Pages | Archives


REPLACE vs. SUBSTITUTE in Excel

July 9, 2016 ^.^

Another pair of functions that has very similar meaning literally.   Although I am not able to tell you the differences between “replace” and “substitute” in English, I can show you the differences of the REPLACE and SUBSTITUTE in Excel.  Are you ready?

Let’s start with the function.  Both functions, as you may guess, look into a text string, then based on your instruction, replace part(s) of a string with any text(s)/character(s) specified.

The key difference between REPLACE and SUBSTITUTE

REPLACE requires you to specify a staring position and length of character you want to replace with something

SUBSTITUTE looks for specific texts/characters and then substitute it with something. Sound like FIND?  If you don’t know FIND, take a look at FIND vs. SEARCH. 

REPLACE

The syntax

REPLACE(old_text, start_num, num_chars, new_text)

All arguments are required.

Picture time:

Excel Tips - Replace vs. Substitute 2.png

In the first example, it tells Excel to look into A1, i.e. “ABCDEabcdeABCDE”, starts with the 5th character for a length of 1, i.e. “E”,  then replace that portion with “_”.

In the second example, the only difference is the third argument num_chars, which is 3.  That means 3 characters starting from the 5th position, i.e. “Eab” in “ABCDEabcdeABCDE”; then replace it with “_”.

Make sense?

Tips:

  1. When the num_chars is larger than the number of characters remained in the text string  from start_num, it replaces all characters from the starting point with the text you specified.
  2. You may input 0 as num_chars.  I think this actually makes the function special.  Try and see what will happen.

SUBSTITUTE

The syntax

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

Comparing to REPLACE, SUBSTITUTE is more simple and intuitive, if you have a specific text in mind… 🙂

Picture time, again:

Excel Tips - Replace vs. Substitute 3.png

In the first example, it looks into the text is A1, look for all “E” (as the last argument is omitted) and then replace with “_”.

Note: SUBSTITUTE is case-sensitive.  If you need to perform case-insensitive SUBSTITUTE, you need to do it together with either LOWER or UPPER…… But this is not a perfect solution.

Do you have a suggestion? Try to figure it out and post it in comment.  In case no answer is posted in comment, I will tell next week. 🙂

 

By the way, is “replace with” the same as “substitute to”??

 

 

 

Rate this:

Posted by MF

Categories: Formula

Tags: ,

2 Responses to “REPLACE vs. SUBSTITUTE in Excel”

  1. Please send me daily newsletter and post

    Like

    By Arun on May 5, 2017 at ^.^

    1. Hi Arun, please follow my blog with your email so that you will get an email when a blog post is published. 😀

      Like

      By MF on May 5, 2017 at ^.^

Leave a Reply



Mobile Site | Full Site


Get a free blog at WordPress.com Theme: WordPress Mobile Edition by Alex King.