REPLACE Function in Excel: Replace Text by Position

REPLACE Function in Excel Replace Text by Position

Have you ever wanted to change only a specific part of text in Excel without changing the entire cell?

For example, you may have product codes with an old year and want to update it. Or you may want to replace the first few digits in a list of phone numbers.

Excel offers two ways to replace text:

  • Find and Replace (Ctrl + H): Use this option to find specific text and replace it with new text in your worksheet.
  • REPLACE Function: Use this function to replace characters based on their position in a text string.

Both methods are useful, but they work differently.

In this article, you will learn how to use Find and Replace and the REPLACE function with simple, practical examples.

What is the REPLACE Function in Excel?

The REPLACE function replaces a specific number of characters in a text string with new text.

You need to tell Excel:

  • Where the replacement should start.
  • How many characters you want to replace.
  • What new text you want to add.

For example, if a cell contains LAP-2025-101 and you want to change 2025 to 2026, you can use the REPLACE function.

REPLACE Function Syntax:

The syntax of the REPLACE function is:

=REPLACE(old_text, start_num, num_chars, new_text)

Let’s understand each argument:

ArgumentDescription
old_textThe original text in which you want to make changes.
start_numThe position where you want to start replacing characters.
num_charsThe number of characters you want to replace.
new_textThe new text you want to insert.

Note: The position starts from 1, counting from the left side of the text.

Examples of the REPLACE Function in Excel

Let’s look at some practical examples to understand how the REPLACE function works.

Example 1: Replace the Year in a Product Code

Suppose you have a list of product codes in column A, and you want to change the year from 2025 to 2026.

Product Code
LAP-2025-101
LAP-2025-102
LAP-2025-103
LAP-2025-104

Here, we want to replace the four characters 2025 with 2026.

Enter this formula in cell B2:

=REPLACE(A2,5,4,”2026″)

Press Enter and drag the formula down.

Result:

Replace the Year in a Product Code Using REPLACE Function

Here:

  • A2 is the original product code.
  • 5 tells Excel to start replacing from the fifth character.
  • 4 tells Excel to replace four characters.
  • “2026” is the new text.

As you can see, only the year changes. The remaining part of the product code stays the same.

Can we do this using Ctrl + H?

Yes! You can simply press Ctrl + H, enter 2025 in Find what, and enter 2026 in Replace with. Excel will replace the matching year in the selected range.

For this example, Find and Replace is the quicker option because we are replacing the same text with the same new text.

But what if you want to replace the first three digits of different phone numbers with 900 while keeping the remaining digits unchanged?

Can Ctrl + H do that automatically? No. This is where the REPLACE function becomes useful.

Example 2: Replace the First Few Characters

Suppose you have a list of phone numbers, and you want to replace the first three digits with 900.

Phone Number
9876543210
9123456780
8765432109
9988776655

To replace the first three digits with 900, enter this formula in cell B2:

=REPLACE(A2,1,3,”900″)

Press Enter and drag the formula down.

Result:

Replace the First Few Characters with REPLACE Function

Here, the formula starts at the first character and replaces three characters with 900.

Notice that the first three digits are replaced, while the remaining seven digits stay unchanged.

Why not use Ctrl + H here?

The first three digits are different in each phone number. We want to replace them with the same three digits while keeping the remaining digits unchanged.

Ctrl + H cannot automatically do this based on character position. The REPLACE function can do it easily using a formula.

Yes! That’s even better. We can show two uses of REPLACE with the same product codes: remove the fourth character and replace it with a hyphen. This demonstrates how the same formula can remove or insert characters.

Example 3: Remove or Replace Special Characters

Suppose you have a list of product codes, and you want to remove the fourth character or replace it with a hyphen.

Product Code
ABC*1001
XYZ#1002
PQR@1003
DEF$1004

1. Remove the fourth character

To remove the fourth character from each product code, enter this formula in cell B2:

=REPLACE(A2,4,1,””)

Press Enter and drag the formula down.

Result:

Remove Special Characters with REPLACE Function

Here, the formula removes the fourth character and replaces it with nothing.

2. Replace the fourth character with a hyphen

Now, suppose you want to replace the fourth character with a hyphen instead of removing it.

Enter this formula in cell C2:

=REPLACE(A2,4,1,”-“)

Press Enter and drag the formula down.

Result:

Replace Special Characters with REPLACE Function

Here, the formula replaces the fourth character with a hyphen (-).

Why not use Ctrl + H?

You can use Ctrl + H to replace a specific character, but here each product code has a different character in the fourth position.

You would need to replace each character separately. With the REPLACE function, you can change the fourth character in all rows using just one formula.

This makes REPLACE useful when you want to remove or replace characters based on their position.

Difference Between REPLACE and SUBSTITUTE Functions in Excel:

Both REPLACE and SUBSTITUTE functions are used to change text in Excel. However, they work in different ways.

  • REPLACE changes text based on its position.
  • SUBSTITUTE changes specific text by searching for the matching word, number, or character.

For example, if you want to change the first three characters of different phone numbers, you can use REPLACE.

If you want to replace every occurrence of a particular word or character, you can use SUBSTITUTE.

Important Things to Know About the REPLACE Function:

  • REPLACE changes text based on character position, not by searching for specific text.
  • The first character in a text string is counted as position 1.
  • You can replace one character or multiple characters at a time.
  • You can use an empty value (“”) to remove characters.
  • REPLACE does not change the original text in the source cell. The updated result appears in the cell where you enter the formula.
  • If you want to replace text by searching for a specific word or character, use the SUBSTITUTE function.

Final Thoughts:

The REPLACE function in Excel helps you change specific characters based on their position in a text string.

You can use it to update product codes, change phone number digits, remove special characters, and much more.

Remember, you don’t always need the REPLACE function. Use Find and Replace (Ctrl + H) when you want to replace the same text or character throughout a range. Use the REPLACE function when you want to change characters based on their position.

Once you understand how it works, you can easily make these changes using a simple formula.


Discover more from Excellopedia

Subscribe to get the latest posts sent to your email.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.