IF Help (Second last chracter in cell matches)

Mr. Alex

New Member
Joined
Nov 26, 2003
Messages
34
Howdy,

I have a column of text like this

F26139
J28661
D798
D29766
D16842_A
D16842_B
D16842_C
D16842_D
J29687_A
J29687_B
J29687_C
J29687_D
C353_A
C353_B
A16484
G28194
G20034
A14916
H18803_A
H18803_B
H18803_C
H18803_D


I need to remove the _A _B _C from the cell, only when present. My column is over 2000 rows long and the _A _B _C shows up everywhere... also, it spans the whole alphabet..

I figure some sort of IF statement would do it, but I need to isolate the underscore _ … It will always be the second last character in the cell.

Any ideas?

Thanks

Mr. Alex
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

al_b_cnu

Well-known Member
Joined
Jul 18, 2003
Messages
4,494
Hi,

Another way is ...
=IF(MID("**"&A1,LEN("**"&A1)-1,1)="_",LEFT(A1,LEN(A1)-2),A1)

HTH

Alan
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,935
Office Version
  1. 365
Platform
  1. Windows
Try:

=IF(MID(A1,LEN(A1)-1,1)="_",LEFT(A1,LEN(A1)-2),A1)
 

onlyadrafter

Well-known Member
Joined
Aug 19, 2003
Messages
5,703
Platform
  1. Windows

ADVERTISEMENT

Hello,

Using a formula

=IF(ISERROR(FIND("_",A1)),A1,LEFT(A1,FIND("_",A1)-1))

or

have you tried find '_?' and replace with nothing?
 

just_jon

Legend
Joined
Sep 3, 2002
Messages
10,473

ADVERTISEMENT

Very well done, fairwinds! :biggrin:
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,935
Office Version
  1. 365
Platform
  1. Windows
=LEFT(A1,FIND("_",A1&" _")-1)

WOW! Now that is a thing of beauty...

I salute you! (y)
 

Mr. Alex

New Member
Joined
Nov 26, 2003
Messages
34
Holy cow, thats sweet man!

Thank you everyone for your help, and Fairwinds for the sweetest bit of code i've seen in quite some time!

I think Fairwinds, if you keep this up, you'll raise the bar for us all. :wink:


Mr. Alex
 

Watch MrExcel Video

Forum statistics

Threads
1,122,719
Messages
5,597,736
Members
414,170
Latest member
Mdm

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
Top