Removing last two characters having alphabets

Deepk

Board Regular
Joined
Mar 21, 2018
Messages
105
Office Version
  1. 2016
Platform
  1. Windows
Hi team,

I have list of entries in an excel column, see example below

AB203467A1
SC345745BB
KC983434T
HE98765P1
AS456382

I want to have a macro that convert these numbers to the following and paste in the next column

AB203467 (A1 removed)
SC345745 (BB removed)
KC983434 (T removed)
HE98765 (P1 removed)
AS456382 (nothing removed)

In short, I want to remove

last two characters if a number is followed by alphabet or both characters are alphabets
only last character if it is alphabet
nothing is removed if there is no alphabet in last two characters.

Please help me with this. Thanks in advance.
 
I have modified your code a bit but its showing an error
It looks like you may be trying to work one cell at a time, rather than processing all at once.
- Is that correct?
- If so, why?
- If I have mis-interpreted, can you explain why the original code was not suitable and what you are trying to achieve with the new code.

If it is simply that you want the code to work on your selected cells rather than column A and assuming that the selection is a single column/row/block of cells, then the change would be
Code:
Sub RemoveAtEndOfSelection()
  With Selection
    .Value = Evaluate(Replace("if(#="""","""",left(#,len(#)-2+if(isnumber(mid(#,len(#)-1,1)+0),1+isnumber(right(#,1)+0),0)))", "#", .Address))
  End With
End Sub
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,224,825
Messages
6,181,189
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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