URGENT!!! remove everything after a second dash in a string (and the second dash)

Jeffrey Green

Well-known Member
Joined
Oct 24, 2007
Messages
1,021
I have this
[TABLE="width: 174"]
<colgroup><col></colgroup><tbody>[TR]
[TD]1174958190-B33TB-DAA[/TD]
[/TR]
[TR]
[TD]1174988827-B33TB-RTR[/TD]
[/TR]
[TR]
[TD]1175002840-B33TB-[/TD]
[/TR]
[TR]
[TD]AC042130-AECNA-AP[/TD]
[/TR]
[TR]
[TD]1175054679-B33TB-

I only want the data BEFORE the second dash[TABLE="width: 174"]
<colgroup><col></colgroup><tbody>[TR]
[TD]1174958190-B33TB[/TD]
[/TR]
[TR]
[TD]1174988827-B33TB[/TD]
[/TR]
[TR]
[TD]1175002840-B33TB[/TD]
[/TR]
[TR]
[TD]AC042130-AECNA[/TD]
[/TR]
[TR]
[TD]1175054679-B33TB[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Try:
Excel Workbook
ABC
11174958190-B33TB-DAA1174958190-B33TB
21174988827-B33TB-RTR1174988827-B33TB
31175002840-B33TB-1175002840-B33TB
4AC042130-AECNA-APAC042130-AECNA
51175054679-B33TB-1175054679-B33TB
Sheet
 
Upvote 0
Hi,

Another way:


Book1
AB
11174958190-B33TB-DAA1174958190-B33TB
21174988827-B33TB-RTR1174988827-B33TB
31175002840-B33TB-1175002840-B33TB
4AC042130-AECNA-APAC042130-AECNA
51175054679-B33TB-1175054679-B33TB
Sheet91
Cell Formulas
RangeFormula
B1=REPLACE(A1,FIND("#",SUBSTITUTE(A1,"-","#",2)),255,"")
 
Upvote 0
Jeffrey Green,

If the following is in cell A1:
1174958190-B33TB-DAA

In cell B1 enter the following formula:
=LEFT(A1,FIND("@",SUBSTITUTE(A1,"-","@",(LEN(A1)-LEN(SUBSTITUTE(A1,"-","")))/LEN("-")))-1)

Cell B1 will display:
1174958190-B33TB

And, then copy cell B1 down to the last used row in column A
 
Upvote 0
You're welcome, glad to contribute.

AhoyNC's formula in Post #2 can also be shortened to this:

=LEFT(A1,FIND("#",SUBSTITUTE(A1,"-","#",2))-1)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
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