Remove Last Character only if not a number

psycoperl

Active Member
Joined
Oct 23, 2007
Messages
338
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))
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
How about
Excel Formula:
=IF(ISNUMBER(--RIGHT(TRIM(E238),1)),TRIM(E238),LEFT(TRIM(E238),LEN(TRIM(E238))-1))
Right will always return text so the ISNUMBER will return False.
 
Upvote 1
Perhaps =IF(ISTEXT(right(E2,1), Left(E2,LEN(E2)-1)+0,E2)
 
Upvote 0
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))
 
Upvote 0
Solution
That is basically doing what I suggested, but in a less efficient way. ;)
 
Upvote 0
In this instance it converts a text number into a number & returns an error if it is a character.
 
Upvote 1
Some other simpler options, depending on whether you can use your 365 version or not.

23 02 23.xlsm
EIJ
238990299029902
239990399039903
240 122L122122
241 123L123123
242 132L132132
243 150B150150
2442002T20022002
2452006L20062006
Num
Cell Formulas
RangeFormula
I238:I245I238=LET(t,TRIM(E238),LEFT(t,LEN(t)-ISERROR(-RIGHT(t,1)))+0)
J238:J245J238=LEFT(TRIM(E238),LEN(TRIM(E238))-ISERROR(-RIGHT(TRIM(E238),1)))+0
 
Upvote 0
We have office 365. Could you please explain these formulas? I would like to know how they are working
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,376
Members
449,080
Latest member
Armadillos

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