Learn how to remove characters from the right of the text using various Excel functions. Discover how to remove the last n characters from a text string.
If you have a data cleaning task, in some cases, we have to keep only the specific parts of a text or string.
You can save your time if you have a versatile Excel toolbox with custom functions. In this article, we will explain the most used formula examples and functions syntaxes.
Generic Formula to Remove Characters from Right
Arguments of the LEFT function:
- text: the text from which you want to remove the last n characters in excel
- numbers_of_characters: the numbers of characters we want to remove.
The argument of the LEN function:
- text: the cell which contains text
Let us examine the formula above! We have some functions to strip characters from the right. But we want to find a solution to make sure everyone clearly understands. So, we’ll apply an inverse formula and try to extract the characters from left.
What should we do? Calculate the result using the following logic:
=(Count the length of the full string) – (N characters from right to left)
How this formula works
As first, we extract the given number (n characters) from the left of the text.
=LEN(A2)-2 = 6
Now we know the proper length of the string. It’s time to execute the second part of the formula. We will use the result as a parameter of the LEFT formula. To remove the last n characters, use a combination of a LEFT and LEN functions.
=LEFT(LEN(A2)-2) =LEFT(6) = Example
TEXTLEFT function to remove characters from right
The TEXTLEFT function did not exist in Excel by default. Fortunately, we have implemented a huge custom function library into our free Excel add-in.
We’ll show you an example to demonstrate the power of the user-defined functions.
Type the formula:
So the unnecessary part of the text will be removed. TEXTLEFT is one of the effective function if you are working with delimiters or wildcards in Excel.
Extract values from right using VALUE
Let’s the next example! We want to extract 855 from cell A5. LEN calculates the total length of the string is in A6. The result is 9.
If you evaluate the
expression, it will return the text ”855”. It’s a text value! We have to convert the text value to number format.
Apply the below formula for the proper result:
Remove the last nth characters using VBA
Because we are familiar with VBA programming, we are working on our main goal: to write better and better time-saving formulas for the Excel community.
Check this example below; it is easy to see how the formula built.
Function RemoveLastNchar(rng As String, counter As Long) RemoveLastNchar = LEFT(rng, LEN(rng) - counter) End Function
Delete the last nth characters from right using an add-in
Use our DataXL productivity tools for Excel and follow these steps below:
- Locate the DataXL tab on the ribbon. Select the cell which contains the text.
- Click on the Text Tools icon. A new window will appear. Select the second tab, Delete.
- Enter the value.
- Example: If you want to remove the last six characters from right, use 6 as a parameter.