OzGrid

How to remove the last X number of characters depending on the ending of the value

< Back to Search results

 Category: [Excel]  Demo Available 

How to remove the last X number of characters depending on the ending of the value

 

Requirement:

 

The user is trying to create a formula where depending on what the ending of the value in the cell is, it deletes 1 or 2 of the last characters.

For example you could have two different codes such as:

AB12-34567-ABC
AB12-34567-AB

The user wants to make a formula that will remove either 1 or two of the last characters to turn it into AB12-34567-A regardless of if there is 2 or 3 characters after the last -

 

Solution:

 

If the objective is consistently to get the first 12 digits ...

Code:
=left(A1,12)

should do the job ...

But if the length before the second - can fluctuate ... you should test :

Code:
=LEFT(A1,IFERROR(FIND(CHAR(1),SUBSTITUTE(A1,"-",CHAR(1),2)),"")+1)

 

Obtained from the OzGrid Help Forum.

Solution provided by Carim.

 

See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets

 

See also:

How to sum cell numerical values based on text suffix
How to sort values in positive and negative numbers with formula
How to use advanced lookup: Multiple criteria when looking up values in a table
How to use multiple match, including a number between two specified values
How to look for value in three different ranges and return one of three results

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.


Gallery



stars (0 Reviews)