Formula? Extract text between 2 characters

boilerup

New Member
Joined
Jul 17, 2019
Messages
10
I need a formula to help the text below...
Company Name (D-0003504825)

to look like this
0003504825_Company Name

On my excel worksheet, all text inside parentheses include "D" then "-" then 10 numbers.

Thanks!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Note: cant simply do formula that finds characters between "-" and ")" because some cells look like this...
Company-Name (D-0003594819)
 
Upvote 0
=MID(A1,FIND("(",A1)+3,10)&"_"&LEFT(A1,FIND("(",A1)-2)

Need more example data to ensure this works properly
 
Upvote 0
HI
What about this for one cell (can easily amended for range of cells If OP likes it)
Suppose the format is always xxxxx xxxxx (D-xxxxxxxxxx)
Code:
Sub teste()
    e = Split(Split(Join(Split(Split(Join(Split(Range("a1"), "(D-"), Chr(22)), ")")(0), "(D-"), Chr(22)), ")")(0), Chr(22))
    Range("b1") = Trim(e(1)) & "_" & e(0)
End Sub

Or
Code:
Sub Test2()
    With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = "(^\w+.\w+)|(\d+)"
        Set spl = .Execute(Range("a1"))
        Range("b1") = spl(1) & "_" & spl(0)
    End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,952
Members
448,535
Latest member
alrossman

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