How to Replace Text between Two Characters in Excel (3 Easy Ways)

Get FREE Advanced Excel Exercises with Solutions!

In this article, we will learn to replace text between two characters in Excel. Sometimes, we import datasets from other sources. Those datasets can contain unnecessary text between two characters. Today, we will show 3 easy methods to replace text quickly. So, without further ado, let’s start the discussion.


How to Replace Text between Two Characters in Excel: 3 Easy Ways

To explain the methods, we will use a dataset that contains information about the Name, IDs, and Departments of some employees. We will try to replace the IDs between the square brackets with some texts.


1. Replace Text between Two Characters with Find and Replace Feature in Excel

The easiest way to replace text between two characters in Excel is to use the Find and Replace feature. It is easy to use and can become very handy in large datasets. Before starting the main process, take a look at the dataset again. Here, we are going to replace the ID numbers with the text ‘Not Available’.

Replace Text between Two Characters with Find and Replace Feature in Excel

Let’s pay attention to the steps below to learn the method.

STEPS:

  • In the beginning, go to the Home tab and select ‘Find & Select’. A drop-down menu will occur.
  • Select Replace from the drop-down menu. It will open the ‘Find and Replace’ dialog box.
  • Alternatively, you can press Ctrl + H on the keyboard to open it.

Replace Text between Two Characters with Find and Replace Feature in Excel

  • Secondly, in the ‘Find what’ field, type an asterisk surrounded by the square brackets [*].
  • After that, you need to type the text in the ‘Replace with’ field. Here, we have typed [Not Available].
  • Then, select Replace All.

Replace Text between Two Characters with Find and Replace Feature in Excel

Note: To replace texts in a single cell, click on the ‘Replace’ button.
  • After selecting Replace All, a message box will appear to show the number of replacements.
  • Click OK to proceed.

Replace Text between Two Characters with Find and Replace Feature in Excel

  • Finally, close the ‘Find and Replace’ dialog box. You will see the ID numbers between the square brackets are replaced.

Replace Text between Two Characters with Find and Replace Feature in Excel

Read More: How to Replace Text in Selected Cells in Excel


2. Use Excel Flash Fill Option for Replacing Text between Two Characters

You can also use the Flash Fill option for replacing text between two characters. The Flash Fill option is available in Excel 2013 and later versions. So, you can’t use this method in the earlier versions. Here, we will use the same dataset. But, we will need another column to apply the Flash Fill.

Let’s follow the steps below to know more.

STEPS:

  • First of all, select Cell E5 and type the desired result. We want to replace 101 with X. So, we have typed Adam [X] (Accounting).

  • In the second step, select the cells where you want to apply the Flash Fill.

Use Excel Flash Fill Option for Replacing Text between Two Characters

  • After that, go to the Home tab and select Fill. A drop-down menu will occur.
  • Select Flash Fill from the drop-down menu.

Use Excel Flash Fill Option for Replacing Text between Two Characters

  • In the end, you will see results like the picture below.

Use Excel Flash Fill Option for Replacing Text between Two Characters

Read More: How to Replace Text with Blank Cell in Excel


3. Insert Excel Formula to Replace Text between Two Characters

In the last method, we will use different functions to create a formula. And with that formula, we will replace text between two characters easily. Here, we will use a combination of IFERROR, SUBSTITUTE, MID, LEFT, FIND, and LEN functions to build the formula. These functions perform different tasks.

To learn the process, follow the steps below.

STEPS:

  • In the first place, select Cell E5.
  • Secondly, type the formula:
=IFERROR(SUBSTITUTE(B5,MID(LEFT(B5,FIND("]",B5)),FIND("[",B5),LEN(B5)),"[X]"),B5)
  • After that, press Enter to see the result.

Insert Excel Formula to Replace Text between Two Characters

  • In the last step, drag the Fill Handle down to copy the formula.

🔎 How Does the Formula Work?

  • LEN(B5)

The LEN function measures the length of a given text string. This part of the formula returns the length of the text string in Cell B5.

  • FIND(“[“,B5)

Here, it searches the “[“ character in the string of Cell B5. As the FIND function is used to search a particular text or substring in a string.

  • MID(LEFT(B5,FIND(“]”,B5)),FIND(“[“,B5),LEN(B5))

We know that the MID function extracts characters from the middle of a text string. To do so, you need to mention the starting position and length of the string. And the LEFT function takes out a specified number of characters from the start of a text string.

In this case, the formula measures the length of the string “[“ from the first position.

  • SUBSTITUTE(B5,MID(LEFT(B5,FIND(“]”,B5)),FIND(“[“,B5),LEN(B5)),”[X]”)

It is the most important part. The SUBSTITUTE function replaces a specific text with a new one in a text string. So, It substitutes text between the square brackets with [X]. You need to write the replacement in the last argument inside the double quotation.

  • IFERROR(SUBSTITUTE(B5,MID(LEFT(B5,FIND(“]”,B5)),FIND(“[“,B5),LEN(B5)),”[X]”),B5)

The IFERROR function ignores the errors and produces a custom result. Generally, it shows the normal result when an error occurs. Here, if the formula returns an error, then the IFERROR function delivers the value of Cell B5.

Read More: Excel Formula to Replace Text with Number


Things to Remember

There are certain things you need to remember when you are trying to replace text between two characters.

  • In Method-1, be careful with the ‘Find and Replace’ dialog box. If you want to replace texts in a single cell, then don’t use ‘Replace All’. Use ‘Replace’ instead.
  • You can’t use Method-2 in Excel 2010 and earlier versions.
  • Be extra careful when you are using Method-3. Because the formula is long and any mistake will return an incorrect result.

Download Practice Book

Download the practice book here.


Conclusion

In this article, we have demonstrated 3 easy methods to Replace Text between two characters in Excel. Here, we have used practical datasets to explain the process. I hope these methods will help you to perform your tasks easily. Furthermore, we have also added the practice book at the beginning of the article. To test your skills, you can download it to exercise. Last of all, if you have any suggestions or queries, feel free to ask in the comment section below.


Related Articles

Mursalin Ibne Salehin
Mursalin Ibne Salehin

Hi there! This is Mursalin. I am currently working as a Team Leader at ExcelDemy. I am always motivated to gather knowledge from different sources and find solutions to problems in easier ways. I manage and help the writers to develop quality content in Excel and VBA-related topics.

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo