Formula to remove all text after second dash and third dash if third dash exist

Sean15

Well-known Member
Joined
Jun 25, 2005
Messages
698
Office Version
  1. 2010
Platform
  1. Windows
Hello:

An online poster posted gave this formula to remove all text after the second dash including the second dash.

LEFT(D19,FIND(" - ",D19,FIND(" - ",D19)+1)-1)

But can formula be adjusted to remove all text after second dash including the second dash and all text after third dash including the third dash if a third dash exist? I working with odd format data and that would be a big help.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Give this a go:
=LEFT(D19,LEN(D19)-FIND("-",(SUBSTITUTE(D19,"-","-",2)))-1)

Change the 2 to a 3, etc.
 
Upvote 0
So how does your data look like?
 
Upvote 0
But can formula be adjusted to remove all text after second dash including the second dash and all text after third dash including the third dash if a third dash exist?
Surely that's what it already does. It removes everything after the 2nd - which also means everything after the 3rd -
 
Upvote 0
@Candyman8019 - your formula is removing all text after first dash.

Data looks like:

XXXXXXX - Cash - 12/1/2021

XXXXXX - Dining Room - Food - 12/1/2021



Required values:

XXXXXXX - Cash

XXXXXX - Dining Room - Food
 
Upvote 0
This will work but does your string always ends with a date?

Excel Formula:
=LEFT(SUBSTITUTE(A26,"-","#",LEN(A26)-LEN(SUBSTITUTE(A26,"-",""))),SEARCH("#",SUBSTITUTE(A26,"-","#",LEN(A26)-LEN(SUBSTITUTE(A26,"-",""))))-2)

When it does end with a date

Excel Formula:
=LEFT(A26,SEARCH("/",A26)-6)
 
Last edited:
Upvote 0
Ok, how about
Excel Formula:
=TEXTJOIN(" - ",,FILTERXML("<k><m>"&SUBSTITUTE(D19," - ","</m><m>")&"</m></k>","//m[position()<last()]"))
 
Upvote 0
Hello:

Thank you so much. I just saw a post at Exceljet with a workable logic, remove characters from the right

LEFT(D19,LEN(D19)-11)

Since I only have to remove 11 characters to the right, the formula suits my needs. But thank you so much for your help.

Sean
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

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