Excel REPLACE function
The REPLACE function in Excel can help you to find and replace characters based on given location from text string with a new text. Take the below screenshot as example, replace 4 characters (2019) which start at the fifth character from the text string with another text string (2020).
- Example 1: Basic uses of the REPLACE function
- Example 2: using REPLACE function with dates
- Example 3: Using REPLACE function to replace text with blank
- Example 4: using REPLACE function to extract username from Email address
The syntax for the REPLACE function in Excel is:
Return a string or text value.
For example, I have a list of text strings, now, I want to replace the first three characters with a specific text as below screenshot shown.
For solving this job, please apply the below formula:
And then, drag the fill handle down to apply this formula to other cells you need, see screenshot:
If you want to replace the day, month or year from a date to other day, month or year as below screenshot shown, the REPLACE function will not get the correct result when using it directly. Here, you should apply the TEXT function to convert the date format to text string firstly, and then use the REPLACE function.
Please apply the following formula:
Then, drag the fill handle down to the cells that you want to sue this formula, and you will get the result as you need:
With this REPLACE function, you can also replace the characters with blank. For example, to replace the first four characters with blank as following screenshot shown.
Please copy or enter the following formula into a blank cell:
And, all the first four characters of the text in each cell has been replaced with a blank. See screenshot:
To extract the username from the Email address, the REPLACE function also can do you a favor.
Enter or copy the following formula into a blank cell:
And then, drag the fill handle down to the cells that you want to apply this formula, and all the usernames from each cell have been extracted at once:
- Excel RIGHT Function
- RIGHT function is used to return the text from right of the text string.
- Excel REPT Function
- The REPT function is used to repeat the characters a specified number of times.
- Excel SEARCH Function
- The SEARCH function can help you to find the position of a specific character or substring from the given text string.