Remove Last Character only if not a number

psycoperl

Active Member
Joined
Oct 23, 2007
Messages
339
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
  3. Web
I am trying to clean up for sorting purposes class catalog #s. To that end, I want to remove any non numeric characters that are at the end of these numbers. For example 2006L should be just 2006, and 2610 would be 2610. Values can range from 1 to 5 characters in length. I tried to use the following formula
Excel Formula:
=IF(ISNUMBER(RIGHT(TRIM(E240),1)),TRIM(E240),LEFT(TRIM(E240),LEN(TRIM(E240))-1))
however it would remove the last character if it was also a digit.

For example 9900 became 990, 9901 became 990, 9902 became 990 also.

Where did I go wrong in the formula?

Book1
CDEI
238BAR01MTH9902990
239BAR01MTH9903990
240BAR01MTH 122L122
241BAR01MTH 123L123
242BAR01MTH 132L132
243BAR01MTH 150B150
244BAR01MTH2002T2002
245BAR01MTH2006L2006
Sheet1
Cell Formulas
RangeFormula
I238:I245I238=IF(ISNUMBER(RIGHT(TRIM(E238),1)),TRIM(E238),LEFT(TRIM(E238),LEN(TRIM(E238))-1))
 
Thank you. I also looked at another forum (not sure if I can name it here) and got the idea to use this formula which worked.

Excel Formula:
=IF(ISNUMBER(RIGHT(TRIM(E255),1)*1),TRIM(E255),LEFT(TRIM(E255),LEN(TRIM(E255))-1))

If the number pattern of only having one letter at the end of a digit string holds, you can take advantage of that to simplify the formula.
Excel Formula:
=LET(X,TRIM(E255),IF(ISNUMBER(X),X,LEFT(X,LEN(X)-1)*1))
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Some other simpler options, depending on whether you can use your 365 version or not.

=LET(t,TRIM(E238),LEFT(t,LEN(t)-ISERROR(-RIGHT(t,1)))+0)
Do you really need the LET and TRIM function calls? This seems to work correctly as far as I can tell...

=0+LEFT(E238,LEN(E238)-ISERR(-RIGHT(E238)))
 
Upvote 0
Do you really need the LET and TRIM function calls?
Depends if there might be any spaces at the right of the original text. Since the OP was using TRIM, I thought that may be a possibility so continued that way.
 
Upvote 0
Depends if there might be any spaces at the right of the original text. Since the OP was using TRIM, I thought that may be a possibility so continued that way.

The system that I am pulling data from can have padded spaces at the front or the end of the string and for sorting purposes I don’t want any of those padding spaces.
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,138
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top