How to extract a particular set of string from a given set of sting?

mailashish123

New Member
Joined
Mar 14, 2019
Messages
12
[FONT=&quot]I am trying to figure out how to remove all data [including opening parenthesis "("] which is appearing after the last occurrence of opening parenthesis "(" in a given string. Refer below example:
[/FONT]


RAW DATAOUTPUT
ABC (P) (L) (30365)ABC (P) (L)
ABC (P) LTD (30365)ABC (P) LTD
ABC P LTD (30365)ABC P LTD

<colgroup><col><col></colgroup><tbody>
</tbody>


<tbody>
</tbody>
I have used this formula in cell B1
=IF(LEN(A1)-LEN(SUBSTITUTE(A1,"(",""))=3,LEFT(A1,FIND("(",A1,FIND("(",A1,FIND("(",A1)+1)+1)-1),IF(LEN(A1)-LEN(SUBSTITUTE(A1,"(",""))=2,LEFT(A1,FIND("(",A1,FIND("(",A1)+1)-1),LEFT(A1,FIND("(",A1)-1)))

[FONT=&quot]I have used the logic in deriving the above formula that how many times "(" is appearing in a text. I have assumed that maximum 3 times "(" this will come so i have used above formula.[/FONT]
[FONT=&quot]The only problem is that the above formula is not dynamic. For example, if the string contains opening parenthesis "(" six times then this formula will not give the desired result.[/FONT]
[FONT=&quot]Can anyone help in giving a new formula/modify the above formula which will be dynamic in nature.[/FONT]
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
you can try PowerQuery (Get&Transform)

Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Extract = Table.TransformColumns(Source, {{"RAW DATA", each Text.BeforeDelimiter(_, " ", {0, RelativePosition.FromEnd}), type text}})
in
    Extract[/SIZE]

RAW DATARAW DATA
ABC (P) (L) (30365)ABC (P) (L)
ABC (P) LTD (30365)ABC (P) LTD
ABC P LTD (30365)ABC P LTD
 
Upvote 0
Hi, and here is a formula based option:


Excel 2013/2016
AB
1RAW DATAOUTPUT
2ABC (P) (L) (30365)ABC (P) (L)
3ABC (P) LTD (30365)ABC (P) LTD
4ABC P LTD (30365)ABC P LTD
5ABC (a) (b) (d) (f) (a) P LTD (30365)ABC (a) (b) (d) (f) (a) P LTD
Sheet1
Cell Formulas
RangeFormula
B2=TRIM(LEFT(A2,FIND("|",SUBSTITUTE(A2,"(","|",LEN(A2)-LEN(SUBSTITUTE(A2,"(",""))))-1))
 
Upvote 0

Forum statistics

Threads
1,214,859
Messages
6,121,963
Members
449,059
Latest member
oculus

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