Formula to get data with specific logic from a string

PANIGGR

New Member
Joined
Sep 4, 2015
Messages
15
I have below data in column A, in this string suffixed with data like "(12345/A76D7YF)". I need numeric and alphanumeric character in two different columns. Please note that customer names before above section may also contain (, ) and /. Uniqueness of column A is that after the last open bracket "(", the required numeric and alphanumeric data comes which may help is building any logic/VBA code

JAMES WALKER(614726/8CZNISNS)

<colgroup><col width="97"></colgroup><tbody>
</tbody>
8CZNISNS
614726
ABC Ltd (306521476/3BAX80ZJ)

<colgroup><col width="97"></colgroup><tbody>
</tbody>
3BAX80ZJ
306521476
Woodside/Ltd (3953084/MZ0QR1LJ)

<colgroup><col width="97"></colgroup><tbody>
</tbody>
MZ0QR1LJ
3953084
Smiths) Ltd (467578/A3RJ67K3K)

<colgroup><col width="97"></colgroup><tbody>
</tbody>
A3RJ67K3K
467578
(Highland/YUYU(5961944/2GN4E1U8)

<colgroup><col width="97"></colgroup><tbody>
</tbody>
2GN4E1U8
5961944

<tbody>
</tbody>
 
.. building any logic/VBA code
Since you mentioned vba code, here is an option for that. This one should produce the alpha-numeric in column B and the numeric in column C as per your first post.

Code:
Sub ExtractData()
  With Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
    .Value = .Offset(, -1).Value
    .Replace What:="*(", Replacement:="", LookAt:=xlPart
    .TextToColumns Destination:=.Offset(, 1).Cells(1), DataType:=xlDelimited, OtherChar:="/", FieldInfo:=Array(Array(1, 1), Array(2, 9))
    .Replace What:="*/", Replacement:="", LookAt:=xlPart
    .Replace What:=")", Replacement:="", LookAt:=xlPart
  End With
End Sub

If you are happy with the results the other way around as per sandy666's sample in post 2 then it can be a tiny bit shorter:

Code:
Sub ExtractData_v2()
  With Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
    .Value = .Offset(, -1).Value
    .Replace What:="*(", Replacement:="", LookAt:=xlPart
    .Replace What:=")", Replacement:="", LookAt:=xlPart
    .TextToColumns DataType:=xlDelimited, OtherChar:="/"
  End With
End Sub
 
Last edited:
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Formula option:

Excel 2012
ABC
1JAMES WALKER(614726/8CZNISNS)8CZNISNS614726
2ABC Ltd (306521476/3BAX80ZJ)3BAX80ZJ306521476
3Woodside/Ltd (3953084/MZ0QR1LJ)MZ0QR1LJ3953084
4Smiths) Ltd (467578/A3RJ67K3K)A3RJ67K3K467578
5(Highland/YUYU(5961944/2GN4E1U8)2GN4E1U85961944
6(Highland/abc(ok)(123456/A23B34XX)A23B34XX123456

<tbody>
</tbody>
Sheet4


Worksheet Formulas
CellFormula
B1=TRIM(SUBSTITUTE(RIGHT(SUBSTITUTE(A1,"/",REPT(" ",LEN(A1))),LEN(A1)),")",""))
C1=TRIM(RIGHT(SUBSTITUTE(LEFT(A1,LEN(A1)-LEN(B1)-2),"(",REPT(" ",LEN(A1))),LEN(A1)))

<tbody>
</tbody>

<tbody>
</tbody>

Thank you
 
Upvote 0
Since you mentioned vba code, here is an option for that. This one should produce the alpha-numeric in column B and the numeric in column C as per your first post.

Code:
Sub ExtractData()
  With Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
    .Value = .Offset(, -1).Value
    .Replace What:="*(", Replacement:="", LookAt:=xlPart
    .TextToColumns Destination:=.Offset(, 1).Cells(1), DataType:=xlDelimited, OtherChar:="/", FieldInfo:=Array(Array(1, 1), Array(2, 9))
    .Replace What:="*/", Replacement:="", LookAt:=xlPart
    .Replace What:=")", Replacement:="", LookAt:=xlPart
  End With
End Sub

If you are happy with the results the other way around as per sandy666's sample in post 2 then it can a tiny bit shorter:

Code:
Sub ExtractData_v2()
  With Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
    .Value = .Offset(, -1).Value
    .Replace What:="*(", Replacement:="", LookAt:=xlPart
    .Replace What:=")", Replacement:="", LookAt:=xlPart
    .TextToColumns DataType:=xlDelimited, OtherChar:="/"
  End With
End Sub

This worked, thank you logical formula sometime takes time if the data is huge. This is is quite easy as compared to power query and logical formula
 
Upvote 0
This worked, thank you logical formula sometime takes time if the data is huge. This is is quite easy as compared to power query and logical formula
You're welcome.

Of course the 'easiness' of a particular solution also depends on your own individual skills & experience. Anyway, you had a good variety of options to choose from. :)
 
Upvote 0
Of course the 'easiness' of a particular solution also depends on your own individual skills & experience.

clapping2.gif
 
Upvote 0

Forum statistics

Threads
1,214,785
Messages
6,121,543
Members
449,038
Latest member
Guest1337

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