Extracting specific text

YasserKhalil

Well-known Member
Joined
Jun 24, 2010
Messages
852
I want to extract a specific text from a string
for example if cell A1 has the value
No way of escaping fate!Do you know that?

I want to extract from the right the string "Do you know that?"
I mean to extract the string depending on exclamation mark !
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I want to extract a specific text from a string
for example if cell A1 has the value
No way of escaping fate!Do you know that?

I want to extract from the right the string "Do you know that?"
I mean to extract the string depending on exclamation mark !
Unfortunately, there are two ways to interpret what you want from the way you used the word "extract".

Does this do what you want...

=MID(A1,FIND("!",A1)+1,LEN(A1))

If it doesn't, then what about this...

=LEFT(A1,FIND("!",A1))
 
Upvote 0
Good but some cells have two exclamation marks and I want just extract after the last one !!!

Then you should have said that in your first post. Try this:

=RIGHT(A1,LEN(A1)-FIND("~",SUBSTITUTE(A1,"!","~",LEN(A1)-LEN(SUBSTITUTE(A1,"!","")))))
 
Upvote 0
Try

=IF(LEN(A1)-LEN(SUBSTITUTE(A1,"!",""))=1,RIGHT(A1,LEN(A1)-FIND("!",A1)),RIGHT(A1,LEN(A1)-FIND("!",SUBSTITUTE(A1,"!","~",1))))
 
Upvote 0
Good but some cells have two exclamation marks and I want just extract after the last one !!!
It would have helped if you had mentioned that originally. Does this formula do what you want...

=TRIM(RIGHT(SUBSTITUTE(A1,"!",REPT(" ",99)),99))
 
Upvote 0
Code:
Function RemoveText(r As String) As String
RemoveText = Mid(r, InStrRev(r, "!") + 1)
End Function

or if you want it blank if there is no exclamation point:

Code:
Function RemoveText(r As String) As String
Dim s As Long
s = InStrRev(r, "!")
If s Then RemoveText = Mid(r, s + 1)
End Function
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,570
Messages
6,179,610
Members
452,931
Latest member
The Monk

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