This post will guide you how to replace all characters before the first match of a specific character with a new text string in excel. How to replace substring before the first occurrence of the comma character with another substring in a text string using excel formula.
Table of Contents
1. Replace all characters before a specific character
If you want to replace characters before the first match of the comma character in a text string in Cell B1, you need to get all characters before the first comma firstly, and we have talked that how to extract text before a specific character in the previous post. So you still need to use the SUBSTITUTE function to replace the old_text with new_text. So you can use the following formula:
=SUBSTITUTE(B1,LEFT(B1,FIND(",",B1,1)-1),"excelhow",1)
Let’s see how this formula works:
=FIND(“,”,B1)-1
This formula returns the position of the first match of the comma character in a text string in Cell B1, then subtract 1 by the position number to get the length of substring before the first comma, so it returns 5. And the returned value goes into the LEFT function as its num_chars argument.
=LEFT(B1,FIND(“,”,B1)-1)
This formula extracts the left-most 5 characters from a text string in Cell B1. So the extracted string goes into the SUBSTITUTE function as its old_text argument.
=SUBSTITUTE(B1,LEFT(B1,FIND(“,”,B1,1)-1),”excelhow”,1)
This formula will replace the first old_text returned by the LEFT function with new_text “excelhow” in a text string in Cell B1.
If you want to replace all old_text with new_text, you just need to remove the third argument of the SUBSTITUTE function, just like the below:
=SUBSTITUTE(B1,LEFT(B1,FIND(",",B1,1)-1),"excelhow")
You will see that all of old_text are replaeced with new text “excelhow” in Cell B1.
2. Replace Text before a specific character using FIND&Select command
You can also use the Find and Replace command to replace text after a specified character, just refer to the following steps:
1# Click “HOME“->”Find&Select”->”Replace…”, then the window of the Find and Replace will appear.
2# click “Replace” Tab, then type e*, into the Find what: text box, and then type “excelhow” string in the Replace with: text box.
3# click “Replace All“
You will see that all characters before the first comma character are replaced with “excelhow” string.
3. Video: replace all characters before the first specific character
This Excel video tutorial, we’ll cover two effective methods for managing text in your spreadsheets. First, we’ll delve into using Excel Formulas to replace all characters before the first match of a specific character. Then, we’ll streamline the process using the Find & Replace feature.
4. Related Formulas
- Remove text after a specific character
If you want to remove all characters after the first match of the comma character in a text string in Cell B1, you can create an excel formula based on the LEFT function and FIND function…… - Remove text before the first match of a specific character
If you want to remove all characters that before the first occurrence of the comma character, you can use a formula based on the RIGHT function, the LEN function and the FIND function….. - Extract word that starting with a specific character
Assuming that you have a text string that contains email address in Cell B1, and if you want to extract word that begins with a specific character “@” sign, you can use a combination with the TRIM function, the LEFT function, the SUBSTITUTE function …. - Extract text before first comma or space
If you want to extract text before the first comma or space character in cell B1, you can use a combination of the LEFT function and FIND function…. - Extract text after first comma or space
If you want to get substring after the first comma character from a text string in Cell B1, then you can create a formula based on the MID function and FIND function or SEARCH function …. - Extract text before the second or nth specific character
you can create a formula based on the LEFT function, the FIND function and the SUBSTITUTE function to Extract text before the second or nth specific character… - Extract text after the second or nth specific character (space or comma)
If you want to extract text after the second or nth comma character in a text string in Cell B1, you need firstly to get the position of the second or nth occurrence of the comma character in text, so you can use the SUBSTITUTE function to replace …
Related Functions
- Excel LEFT function
The Excel LEFT function returns a substring (a specified number of the characters) from a text string, starting from the leftmost character.The LEFT function is a build-in function in Microsoft Excel and it is categorized as a Text Function.The syntax of the LEFT function is as below:= LEFT(text,[num_chars])…t)… - Excel FIND function
The Excel FIND function returns the position of the first text string (sub string) within another text string.The syntax of the FIND function is as below:= FIND(find_text, within_text,[start_num])… - Excel Substitute function
The Excel SUBSTITUTE function replaces a new text string for an old text string in a text string.The syntax of the SUBSTITUTE function is as below:= SUBSTITUTE (text, old_text, new_text,[instance_num])….
Leave a Reply
You must be logged in to post a comment.