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]


[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][TABLE="width: 318"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]RAW DATA[/TD]
[TD]OUTPUT[/TD]
[/TR]
[TR]
[TD]ABC (P) (L) (30365)[/TD]
[TD]ABC (P) (L) [/TD]
[/TR]
[TR]
[TD]ABC (P) LTD (30365)[/TD]
[TD]ABC (P) LTD [/TD]
[/TR]
[TR]
[TD]ABC P LTD (30365)[/TD]
[TD]ABC P LTD [/TD]
[/TR]
</tbody>[/TABLE]

[/TD]
[/TR]
</tbody>[/TABLE]
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

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
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]

[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td=bgcolor:#5B9BD5]RAW DATA[/td][td][/td][td=bgcolor:#70AD47]RAW DATA[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]ABC (P) (L) (30365)[/td][td][/td][td=bgcolor:#E2EFDA]ABC (P) (L)[/td][/tr]

[tr=bgcolor:#FFFFFF][td]ABC (P) LTD (30365)[/td][td][/td][td]ABC (P) LTD[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]ABC P LTD (30365)[/td][td][/td][td=bgcolor:#E2EFDA]ABC P LTD[/td][/tr]
[/table]
 
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,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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