Extract Text After second dash?

excelbetter

Board Regular
Joined
Oct 13, 2010
Messages
190
I have a sheet with over 20,000 rows of item #'s in Column A of a sheet.

I am looking to:

1) Find all items that have 2 dashes (i.e. "-"), then...

2) For those that have 2 dashes, in a new column, put the contents of the item # that come after the second dash.

Sample data is below:

abc-scott-special
kjh-jkhsakjjkhkjh-SAM
CB-123456jkh-bob
EX-1824ABCXYZ-justoneday
AB-123455
AB-765432
AB-NOSECONDDASH
AB-TWODASHES-testhere


You'll see some of the above has 2 dashes, and some only have one.

Any thoughts on how to do this?

Thanks a million!
 
BINGO. Wow, I can't believe I missed that. So obvious. Thanks a bunch. Problem solved!

Why can't you just do a text-to-columns on the original data column and delimit by "-". This will result in 3 columns. Sort the 3rd column so all spaces are moved to the bottom of the column.
 
Upvote 0

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
OK...Perhaps this, then (copied down):
Code:
B1: =MID(A1,FIND("|",SUBSTITUTE(A1,"-","|",2)&"|")+1,255)

Does that help?
 
Upvote 0
Thanks Ron. This is very close however some of the results are wrong. Not all of the item #'s have two dashes, some only have one dash. I am trying to only find those that have 2 dashes, and for those that have two, to pull out the contents of what is after the second dash. Does that make sense? LMK. Thank you.

Add a test expression to the suggested formula...

=IF(LEN(A1)-LEN(SUBSTITUTE(A1,"-",""))>1,TRIM(RIGHT(SUBSTITUTE(A1,"-",REPT(" ",LEN(A1))),LEN(A1))),"")
 
Upvote 0
The following will also give the results you are looking for. It is written to work with either Excel 2003 or Excel 2007.

=IF(ISERROR(FIND("^^",SUBSTITUTE(A1,"-","^^",2))),"BLANK SINCE THERE IS ONLY 1 DASH",MID(A1,FIND("^^",SUBSTITUTE(A1,"-","^^",2)),LEN(A1)-FIND("^^",SUBSTITUTE(A1,"-","^^",2))+1))
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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