remove after last "-" not working

dmj120

Active Member
Joined
Jan 5, 2010
Messages
286
Office Version
  1. 365
  2. 2019
  3. 2010
I'm trying to remove text after the second hyphen. Some cells have only one hyphen, while others have two. The below formula works with one hyphen

in C2 I have =LEFT(B2,FIND("@",SUBSTITUTE(B2,"-","@",LEN(B2)-LEN(SUBSTITUTE(B2,"character",""))))-1)

Example:
Col BCol C - desired result
sicu - r2sicu
burnt - d9burnt
A3 - OPP - R7A3 - OPP
QPP - Ops - dev9OPP - Ops
QPP - Ops - dev9OPP ----- what my formula outputs


Where am I making a mistake?

Thanks
Josh
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi,

If I understand correctly:

Book3.xlsx
BC
1
2sicu - r2sicu - r2
3burnt - d9burnt - d9
4A3 - OPP - R7A3 - OPP
5QPP - Ops - dev9QPP - Ops
6QPP - Ops - dev9QPP - Ops
Sheet937
Cell Formulas
RangeFormula
C2:C6C2=TRIM(LEFT(SUBSTITUTE(B2,"-",REPT(" ",99),2),99))

Not quite. Most of the cells in col.C only have have one hyphen, which works correctly.

In your example C4-C6 are correct, but C2 and C3 needs to be just sicu and burnt, respectively. This is the challenge I've been having.
 
Upvote 0
Like this?

22 01 26.xlsm
BC
1
2sicu - r2sicu
3burnt - d9burnt
4A3 - OPP - R7A3 - OPP
5QPP - Ops - dev9QPP - Ops
6QPP - Ops - dev9QPP - Ops
dmj120
Cell Formulas
RangeFormula
C2:C6C2=TRIM(LEFT(B2,FIND("@",SUBSTITUTE(B2,"-","@",LEN(B2)-LEN(SUBSTITUTE(B2,"-",""))))-1))
 
Upvote 0
Not quite. Most of the cells in col.C only have have one hyphen, which works correctly.

In your example C4-C6 are correct, but C2 and C3 needs to be just sicu and burnt, respectively. This is the challenge I've been having.

Well, the confusion is, your original formula, aside from the typo "character", should be "-" works:

Book3.xlsx
BC
1
2sicu - r2sicu
3burnt - d9burnt
4A3 - OPP - R7A3 - OPP
5QPP - Ops - dev9QPP - Ops
6QPP - Ops - dev9QPP - Ops
Sheet937
Cell Formulas
RangeFormula
C2:C6C2=LEFT(B2,FIND("@",SUBSTITUTE(B2,"-","@",LEN(B2)-LEN(SUBSTITUTE(B2,"-",""))))-1)
 
Upvote 0
your original formula, aside from the typo "character", should be "-" works:
.. apart from it leaves (or may leave) a space character on the end which I assumed would not be wanted - hence added the TRIM function.
 
Upvote 0
.. apart from it leaves (or may leave) a space character on the end which I assumed would not be wanted - hence added the TRIM function.

Thanks Peter!!! I wasn't thinking about an ending space. (y)??
 
Upvote 0
Well, the confusion is, your original formula, aside from the typo "character", should be "-" works:
.. apart from it leaves (or may leave) a space character on the end which I assumed would not be wanted - hence added the TRIM function.

I was just addressing why I was not sure, or confused, since OP formula works, therefore I thought OP wanted Only to remove after 2nd "-"

Regarding the extra space OP can change "-1" to "-2" in formula, or use TRIM as you suggested.
 
Upvote 0
Here is another formula that you can try...
Excel Formula:
=TRIM(LEFT(B2,IFERROR(FIND("@",SUBSTITUTE(B2,"-","@",2)),FIND("-",B2))-1))
 
Upvote 0

Forum statistics

Threads
1,215,328
Messages
6,124,299
Members
449,149
Latest member
mwdbActuary

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