How to Remove Prefix and Suffix in Excel [11 Methods]
A prefix and a suffix are specific sequences of characters that appear at the beginning (prefix) or the end (suffix) of a string or word. They are often used to add context, information, or structure to text data. Removing prefixes and suffixes in Excel involves eliminating specific text that appears at the beginning (prefix) or end (suffix) of a cell’s content, leaving only the core or desired portion of the text. In this article, I will show you 11 different methods to remove prefixes and suffixes in Excel.
Case 1: Remove Prefix or Suffix Separately
Removing prefixes and suffixes from strings in Excel is a common task when you need to clean or extract specific information from your data. In this type of case first we try to remove prefixes and then we try to remove suffixes.
Remove Prefix and Suffix Separately by Applying the Find and Replace Option
The Find and Replace command may come in handy to remove specific characters in some special circumstances. It is the easiest method to remove suffixes and prefixes in Excel.
To remove prefixes, apply the Find and Replace option. The process is given below:
- First, choose cell (C2:C10) and press CTRL+C to copy the selected texts.
- Then choose cell (D2:D10) and press CTRL+V to paste those selected texts.
- After pasting, again choose cell (D2:D10) and press CTRL+F to open the Find and Replace dialog box.
- In the Find and Replace dialog box, type “STU” in the “Find What” box and leave the “Replace With” box blank.
- Finish the process after clicking the “Replace All” button and a pop-up message will confirm all the replacements.
Final Result for Removing Prefix
After that, we can see that all prefixes are removed.
Utilize the Find and Replace function to get rid of suffix. The steps are listed below:
- First, choose cell (C2:C10) and press CTRL+C to copy the selected texts.
- Then choose cell (D2:D10) and press CTRL+V to paste those selected texts.
- After pasting, again choose cell (E2:E10) and press CTRL+F to open the Find and Replace dialog box.
- In the Find and Replace dialog box, type “-NSU” in the “Find What” box and leave the “Replace With” box blank.
- Finish the process after clicking the “Replace All” button and a pop-up message will confirm all the replacements.
Final Result for Removing Suffix
Here we can see that all Suffixes are removed.
Remove Prefix and Suffix Separately Using Flash Fill Feature
Flash Fill is a feature in Microsoft Excel that helps you quickly clean, format, or transform data in a column without writing complex formulas or using manual data manipulation techniques. It automatically detects patterns in your data and fills in values or extracts information accordingly. However, the Flash Fill feature is available only in Microsoft Excel 2013 and later versions.
Use the Flash Fill feature and remove the prefix. Here’s how:
- Select a cell (D2) and type 44297-NSU manually without typing the prefix.
- Then select the next cell (D3).
- Go to Data.
- After that select Flash Fill from the Data Tools group. Or, click CTRL+E.
Final Result for Removing Prefix
After applying Flash Fill we can see that the prefixes from the Dataset have been removed.
Utilize the Flash Fill function to eliminate the suffix. Here’s how to do it:
- Select a cell (E2) and type STU44297 manually without typing the prefix.
- Then select the next cell (E3).
- Go to Data.
- After that select Flash Fill from the Data Tools group. Or, click CTRL+E.
Final Result for Removing Prefix
Finally, we can see that Flash Fill removes the Suffixes from the Dataset.
Remove Prefix and Suffix Separately Using RIGHT & LEN and LEFT & LEN Functions
One of the easiest ways to remove the last digit in Excel is by using the RIGHT-LEN and LEFT-LEN combinations. The LEFT function removes a specified number of characters from the left side of a string on the other hand, the RIGHT function removes the number of characters from the right side of a string. Now follow the steps below to see how it works.
Syntax for Removing Prefix
=RIGHT(text, LEN(text)-1)
Remove Prefix Formula
=RIGHT(C2, LEN(C2)-3)
Syntax of Removing Suffix
=LEFT(text, LEN(text)-1)
Formula to Remove Suffix
=LEFT(C2,LEN(C2)-4)
Formula Breakdown for Removing Prefix
- C2: It is the cell reference. This is the cell from which you want to extract the text.
- LEN(C2): Calculates the length (number of characters) of the text in cell C2.
- LEN(C2)-3: Subtracts 3 from the length calculated in the previous step.
- RIGHT(C2, LEN(C2)-3): Takes the rightmost characters from cell C2. It extracts as many characters as specified by the result of LEN(C2)-3.
The LEFT & LEN functions also work in the same way.
To remove prefixes, use the RIGHT & LEN functions. Here’s how:
- Copy the RIGHT & LEN combination formula above.
- Apply the formula in cell C2.
- Drag the Fill Handle from cell D2 to D10.
Final Result for Removing Prefix
After applying RIGHT & LEN we can see that the prefixes from the dataset have been removed.
To remove suffixes, use LEFT & LEN functions. Here’s how:
- Copy the LEFT & LEN combination formula above.
- Apply the formula in cell E2.
- Drag the Fill Handle from cell E2 to E10.
Final Result for Removing Suffix
Here all suffixes from every cell have been removed by using the LEFT & LEN Functions.
Remove Prefix and Suffix Separately by Using REPLACE Function
The REPLACE function is used to replace a specified number of characters in a text string with new text. It is commonly used for text manipulation and data-cleaning tasks. The methods below will show you how to replace suffixes and prefixes in Excel using the REPLACE function.
Syntax
= REPLACE(old_text, start_num, num_chars, new_text)
Formula for Removing Prefix
=REPLACE(C2,1,3,"")
Formula for Removing Suffix
=REPLACE(C2,9,4,"")
Formula Breakdown
- This formula is using the REPLACE function in Excel.
- It operates on the cell C2. The function takes four arguments: the original text (C2), the starting position (1), the number of characters to replace (3), and the replacement text (“” – an empty string).
- In essence, it removes the first three characters from the content of cell C2 and replaces them with nothing, effectively deleting them.
The formula for removing suffixes also works like this.
You can also insert the REPLACE function to remove prefixes, by following the steps below:
- Copy the formula for removing prefixes.
- Apply the formula in cell D2.
- Drag the Fill Handle from D2 to D10.
Final Result for Removing Prefix
After that, all prefixes from every cell have been removed by using the REPLACE Function.
You can also insert the REPLACE function to remove suffixes, by following the steps below:
- Copy the formula for removing prefixes.
- Apply the formula in cell E2.
- Drag the Fill Handle from E2 to E10.
Final Result for Removing Suffix
Here we see that all suffixes from every cell have been removed by using the REPLACE Function.
Remove Prefix and Suffix Separately by Applying SUBSTITUTION Function
An alternative way to remove the special character is using a SUBSTITUTE function. It is used to replace a character with another. The dataset for this SUBSTITUTE function is given below.
Syntax
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(text,old_text,new_text),old_text,new_text),old_text,new_text)
Formula for Removing Prefix
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C2,"S",""),"T",""),"U","")
Removing Suffix Formula
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C2,"B",""),"Y",""),"D",""),"-","")
Formula Explanation
This formula is a nested use of the SUBSTITUTE function in Excel, applied to the content of cell C2. It replaces occurrences of the letters “S,” “T,” and “U” with an empty string (“”), effectively removing these letters from the original text. The nested structure indicates sequential substitution, where each inner SUBSTITUTE function operates on the result of the previous one. In summary, this formula transforms the content of cell C2 by eliminating occurrences of the specified letters “S,” “T,” and “U.”
Follow the steps below to remove the prefix by using the SUBSTITUTE function:
- Copy the formula for removing prefixes.
- Apply the formula in cell D2.
- Drag the Fill Handle from D2 to D10.
Final Result for Removing Prefix
As a result, all prefixes from every cell have been removed.
To use the SUBSTITUTE function to remove a suffix, follow these steps:
- Copy the formula for removing suffixes.
- Apply the formula in cell E2.
- Drag the Fill Handle from E2 to E10.
Final Result for Removing Suffix
Here we see that the SUBSTITUTE Function removes all suffixes from every cell.
Applying VBA code to Remove Prefix and Suffix Separately
Another approach is to use VBA code to remove special characters from Excel. VBA (Visual Basic for Applications) in Excel is a programming language that allows you to automate tasks, create custom functions, and build applications within Microsoft Excel.
Apply VBA code and remove the prefix. Here’s how:
- Go to Developer and select Visual Basic or press ALT+F11.
- This will open the Visual Basic Editor.
- Then select Insert and create a Module.
- Copy the code below and paste it into the newly created module.
Sub RemovePrefix() Dim inputRange As Range Dim outputRange As Range Dim prefixDigits As Integer Dim cell As Range Dim inputCell As Range Dim result As String ' Prompt the user to select the input range On Error Resume Next Set inputRange = Application.InputBox("Select the range containing text with prefix:", Type:=8) On Error GoTo 0 ' Exit if no input range is selected If inputRange Is Nothing Then Exit Sub End If ' Prompt the user to select the output range On Error Resume Next Set outputRange = Application.InputBox("Select a single cell where you want to start placing the modified text:", Type:=8) On Error GoTo 0 ' Exit if no output range is selected If outputRange Is Nothing Then Exit Sub End If ' Prompt the user for the number of digits in the prefix prefixDigits = InputBox("Enter the number of digits in the prefix:") ' Loop through each cell in the input range For Each inputCell In inputRange If Not IsEmpty(inputCell.Value) Then ' Check if the cell is not empty result = inputCell.Value ' Remove the prefix based on the specified number of digits If Len(result) >= prefixDigits Then result = Mid(result, prefixDigits + 1) End If ' Place the modified text in the corresponding cell of the output range outputRange.Value = result ' Move to the next cell in the output range Set outputRange = outputRange.Offset(1, 0) End If Next inputCell End Sub
- Save the code by pressing CTRL+S.
- Go to Developer and click the Macros button or you can easily open the Macro dialog box by pressing ALT+F8.
- Click Run by selecting RemovePrefix.
- Select the range C2:C10 and click OK.
- Select cell D2 and click OK.
- Enter the number of digits in the prefix and click OK.
Final Result for Removing Prefix
By doing these steps we can remove the prefix.
Run the VBA code to remove the suffix. Here’s how to do it:
- Press ALT+F11 to open the Visual Basic Editor.
- Then a new window will be opened and select Insert and Create a Module.
- Copy the code below and paste it.
Sub RemoveSuffix() Dim inputRange As Range Dim outputRange As Range Dim suffixDigits As Integer Dim cell As Range Dim inputCell As Range Dim result As String ' Prompt the user to select the input range On Error Resume Next Set inputRange = Application.InputBox("Select the range containing text with suffix:", Type:=8) On Error GoTo 0 ' Exit if no input range is selected If inputRange Is Nothing Then Exit Sub End If ' Prompt the user to select the output range On Error Resume Next Set outputRange = Application.InputBox("Select a single cell where you want to start placing the modified text:", Type:=8) On Error GoTo 0 ' Exit if no output range is selected If outputRange Is Nothing Then Exit Sub End If ' Prompt the user for the number of digits in the suffix suffixDigits = InputBox("Enter the number of digits in the suffix:") ' Loop through each cell in the input range For Each inputCell In inputRange If Not IsEmpty(inputCell.Value) Then ' Check if the cell is not empty result = inputCell.Value ' Remove the suffix based on the specified number of digits If Len(result) >= suffixDigits Then result = Left(result, Len(result) - suffixDigits) End If ' Place the modified text in the corresponding cell of the output range outputRange.Value = result ' Move to the next cell in the output range Set outputRange = outputRange.Offset(1, 0) End If Next inputCell End Sub
- Save the code by pressing CTRL+S.
- Press ALT+F8 to open the Macro dialog box.
- Click Run after selecting RemoveSuffix.
- Select the range C2:C10 and click OK.
- Select cell E2 and click OK.
- Enter 4 as the number of digits in the suffix and click OK.\
Final Result for Removing Suffix
Finally, we see that the suffix has been removed.
Case 2: Remove Prefix and Suffix Simultaneously
When you need to clean up or extract particular information from your data, removing prefixes and suffixes from strings in Excel is a regular operation. Here we discussed how we could remove prefixes and suffixes simultaneously.
Applying Flash Fill Tool to Remove Prefix and Suffix Simultaneously
We can use the Flash Fill feature to remove both suffixes and prefixes instantly. It is the easiest method.
Apply the Flash Fill tool and remove prefixes and suffixes simultaneously. Follow the steps below:
- Select a cell (D2) and type 44297 manually without typing the prefix and Suffix.
- Then select the next cell (D3).
- Go to Data.
- After that select Flash Fill from the Data Tools group. Or, click CTRL+E.
Final Result
After applying Flash Fill we can see that the prefixes and suffixes from the dataset have been removed.
Applying the Find and Replace Option to Remove Prefix and Suffix Simultaneously
The Find and Replace command can be used to remove suffixes and prefixes in some special circumstances.
Follow these steps to remove prefixes and suffixes simultaneously by applying the Find and Replace option:
- First, choose cell (C2:C10) and press CTRL+C to copy the selected texts.
- Then choose cell (D2:D10) and press CTRL+V to paste those selected texts.
- Choose cell (D2:D10) and press CTRL+F to open the Find and Replace dialog box.
- In the Find and Replace dialog box, type “STU” in the “Find What” box and leave the “Replace With” box blank.
- Finish the process after clicking the “Replace All” button and a pop-up message will confirm all the replacements.
- First, choose cell (D2:D10) and press CTRL+C to copy the selected texts.
- Then choose cell (E2:E10) and press CTRL+V to paste those selected texts.
- Choose cell (E2:E10) and press CTRL+F to open the Find and Replace dialog box.
- In the Find and Replace dialog box, type “-NSU” in the “Find What” box and leave the “Replace With” box blank.
- Finish the process after clicking the “Replace All” button and a pop-up message will confirm all the replacements.
Final Result
Here all the prefixes and suffixes are removed.
Using MID and LEN Functions to Remove Prefix and Suffix Simultaneously
Here, we’ll use Excel’s MID and LEN functions to get rid of the prefixes and suffixes. We are using these two functions to eliminate the first three and last four characters from our dataset. Please follow the instructions below to remove the prefixes using the MID and LEN functions.
Syntax
=MID(text, LEN(text)-1)
Formula
=MID(C2, LEN("STU") + 1, LEN(C2) - LEN("STU") - LEN("-NSU"))
Formula Breakdown
This formula utilizes the MID function in Excel to extract a substring from the content of cell C2.
- The MID function takes three arguments: the original text (C2), the starting position (calculated as the length of “STU” plus 1), and the number of characters to extract (calculated as the length of C2 minus the combined length of “STU” and “-NSU”).
- In essence, this formula extracts a portion of the text in cell C2, starting from the position immediately following “STU” and ending just before the characters “-NSU.” The result is a substring without “STU” and its preceding hyphen.
Use MID and LEN functions to remove prefixes and suffixes simultaneously. Follow these steps:
- Copy the MID & LEN formula above.
- Paste the formula in cell C2.
- Drag the Fill Handle from cell D2 to D10.
Final Result
Here we see, that all the prefixes and suffixes are removed.
Applying the Nested SUBSTITUTE Function to Remove Prefix and Suffix Simultaneously
One of the common methods to remove prefixes and suffixes is the SUBSTITUTE formula. Here it is given below:
Syntax
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(text,old_text,new_text),old_text,new_text),old_text,new_text)
Formula
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C2,"S",""),"T",""),"U",""),"B",""),"Y",""),"D",""),"-",""),"N","")
Formula Breakdown
- This Excel formula employs a series of nested SUBSTITUTE functions to manipulate the content of cell C2.
- It systematically replaces occurrences of the letters “S,” “T,” “U,” “B,” “Y,” “D,” the hyphen “-“, and “N” with an empty string (“”), effectively removing these characters from the original text.
In summary, the formula progressively eliminates specified letters and the hyphen, transforming the content of cell C2 by iteratively substituting each targeted character with nothing.
To simultaneously eliminate the prefix and suffix, use the SUBSTITUTE function. Take these actions:
- Copy the above formula.
- Apply the formula in cell D2.
- Drag the Fill Handle from D2 to D10.
Final Result
Finally, the SUBSTITUTE Function removes all prefixes and suffixes from every cell.
Applying VBA Code to Remove Prefix and Suffix Simultaneously
The final method to remove prefixes and suffixes simultaneously is by applying VBA code.
Use VBA code to remove prefixes and suffixes simultaneously. The process is given below:
- Press ALT+F11 to open Visual Basic Editor.
- Then select Insert > Module.
- Copy the code below and paste it.
Sub RemovePrefixAndSuffix() Dim inputRange As Range Dim outputRange As Range Dim prefixDigits As Integer Dim suffixDigits As Integer Dim cell As Range Dim inputCell As Range Dim result As String ' Prompt the user to select the input range On Error Resume Next Set inputRange = Application.InputBox("Select the range containing text with prefix and suffix:", Type:=8) On Error GoTo 0 ' Exit if no input range is selected If inputRange Is Nothing Then Exit Sub End If ' Prompt the user to select the output range On Error Resume Next Set outputRange = Application.InputBox("Select a single cell where you want to start placing the modified text:", Type:=8) On Error GoTo 0 ' Exit if no output range is selected If outputRange Is Nothing Then Exit Sub End If ' Prompt the user for the number of digits in prefix and suffix prefixDigits = InputBox("Enter the number of digits in the prefix:") suffixDigits = InputBox("Enter the number of digits in the suffix:") ' Loop through each cell in the input range For Each inputCell In inputRange If Not IsEmpty(inputCell.Value) Then ' Check if the cell is not empty result = inputCell.Value ' Remove the prefix and suffix based on the specified number of digits If Len(result) >= prefixDigits Then result = Mid(result, prefixDigits + 1) End If If Len(result) >= suffixDigits Then result = Left(result, Len(result) - suffixDigits) End If ' Place the modified text in the corresponding cell of the output range outputRange.Value = result ' Move to the next cell in the output range Set outputRange = outputRange.Offset(1, 0) End If Next inputCell End Sub
- Save the module by pressing CTRL+S.
- Now press ALT+F8 to open the Macro dialog box.
- Select RemovePrefixSuffix and hit the Run button.
- Select the range C2:C10 and click OK.
- Select cell D2 and click OK.
- Enter 3 as the number of digits in the prefix and click OK.
- Enter 4 as the number of digits in the suffix and click OK.
Final Result
Finally, we see that the prefix and suffix have been removed.
Conclusion
In this article, I’ve discussed two types of cases to remove prefixes and suffixes. One case is separately removing prefixes and suffixes and another is removing prefixes and suffixes at the same time. I have used Flash Fill, Find and Replace, SUBSTITUTE, RIGHT, LEFT, and LEN functions. By following these methods you can easily remove prefixes and suffixes in Excel.
Frequently Asked Questions (FAQs)
How do I remove prefix and suffix spaces in Excel?
To remove both prefix and suffix spaces in Excel, you can use the TRIM function.
- Simply apply the formula as follows: =TRIM(A1)
- Replace “A1” with the reference to the cell containing the text with spaces.
- This formula trims leading and trailing spaces, ensuring that only the content without any leading or trailing spaces is displayed.
How do I remove the prefix 00 in Excel?
To remove the prefix “00” from a cell in Excel, you can use the SUBSTITUTE function.
- Assuming the data is in cell A1, you can use the following formula: =IF(LEFT(A1,2)=”00″, RIGHT(A1, LEN(A1)-2), A1)
- This formula checks if the first two characters of the cell A1 are “00”.
- If they are, it removes them by taking the right part of the string starting from the third character.
- If the prefix is not present, it returns the original content of the cell. Adjust the cell references as needed based on your data.
How do I remove prefix currency in Excel?
To remove a currency prefix from a cell in Excel, you can use a combination of functions like SUBSTITUTE and VALUE.
- Assuming your currency values are in column A, you can use the following formula: =VALUE(SUBSTITUTE(A1,”$”,””))
- This formula assumes that the currency symbol is “$”. Replace “$” with the actual currency symbol used in your data.
- It uses the SUBSTITUTE function to replace the currency symbol with an empty string and then the VALUE function to convert the result into a numeric value.
- Adjust the cell references based on your data location.