Extract text before the last occurrence of a character

rongrace

New Member
Joined
Feb 23, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I want to extract the data before the last occurrence of a character, for example, cell contains 'T10_Shorter_2016'. I want to extract 'T10_Shorter'

I tfound the following =LEFT(A1,FIND("_",SUBSTITUTE(A1,"#","_",LEN(A1)-LEN(SUBSTITUTE(A1,"_",""))))-1) and tried to use it, but excel told me it wasn't a formula

I assume there's a problem with the syntax, but I can't see what

Any help would be appreciated
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi & welcome to MrExcel.
There is nothing wrong with that formula, however from your description I think it should be
Excel Formula:
=LEFT(A1,FIND("#",SUBSTITUTE(A1,"_","#",LEN(A1)-LEN(SUBSTITUTE(A1,"_",""))))-1)
 
Upvote 0
Hi & welcome to MrExcel.
There is nothing wrong with that formula, however from your description I think it should be
Excel Formula:
=LEFT(A1,FIND("#",SUBSTITUTE(A1,"_","#",LEN(A1)-LEN(SUBSTITUTE(A1,"_",""))))-1)
Hi Fluff, thanks for your help, that works perfectly
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
or in 365 you can use:
Excel Formula:
=TEXTBEFORE("T10_Shorter_2016","_",-1)
 
Upvote 0
You can use that now, but that function was not available back in Feb 2022.
 
Upvote 0

Forum statistics

Threads
1,223,262
Messages
6,171,080
Members
452,377
Latest member
bradfordsam

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