Formula for removing text within multiple sets of parentheses

mbeyer

New Member
Joined
May 21, 2014
Messages
10
Hello, Mr. (and Mrs.) Excel!

Anyone know of a formula for removing text within multiple sets of parentheses?

I would like to take something like this:
Compared with placebo, dimethyl fumarate was shown to be effective in the treatment of patients with MS in the phase 3 DEFINE (Gold R et al. N Engl J Med. 2012; 367:1098-1107) and CONFIRM (Fox R et al. N Engl J Med. 2012;367:1087-1097) trials. Common adverse effects associated with dimethyl fumarate that were observed in these trials included flushing and GI events, as well as decreased lymphocyte counts and elevated liver aminotransferase levels.

and have it read:
Compared with placebo, dimethyl fumarate was shown to be effective in the treatment of patients with MS in the phase 3 DEFINE and CONFIRM trials. Common adverse effects associated with dimethyl fumarate that were observed in these trials included flushing and GI events, as well as decreased lymphocyte counts and elevated liver aminotransferase levels.

I wish to automate this task so formulas (if possible) are preferred. Totally cool with a multi-formula, many-columned solution - as long as this task is automated.

NB: Each cell will contain different text, so the sets of parentheses will appear in different places. The number of parenthetical sets may also vary from 1-5.

THANK YOU, THANK YOU!!!!! This board is the best!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Maybe the code I posted here will work for you...

Trim all Cells in a Worksheet - VBA

Ignore the above (well, you can take note of it, but it has nothing to do with the extra spaces you see)... those extra spaces are normal space characters and result from your closing parentheses resting next to a punctuation mark (actually, the resulting space is the one in front of the opening parenthesis)... the Application.Trim function call does nothing to remove them. Here is my NoParens function revised to handle this problem...
Code:
Function NoParens(S As String) As String
  Dim X As Long, Parts() As String
  Parts = Split(Replace(Replace(S, " (", "("), ")", "("), "(")
  For X = 1 To UBound(Parts) Step 2
    Parts(X) = ""
  Next
  NoParens = Application.Trim(Join(Parts, " "))
End Function
 
Last edited:
Upvote 0
Ignore the above (well, you can take note of it, but it has nothing to do with the extra spaces you see)... those extra spaces are normal space characters and result from your closing parentheses resting next to a punctuation mark (actually, the resulting space is the one in front of the opening parenthesis)... the Application.Trim function call does nothing to remove them. Here is my NoParens function revised to handle this problem...
Code:
Function NoParens(S As String) As String
  Dim X As Long, Parts() As String
  Parts = Split(Replace(Replace(S, " (", "("), ")", "("), "(")
  For X = 1 To UBound(Parts) Step 2
    Parts(X) = ""
  Next
  NoParens = Application.Trim(Join(Parts, " "))
End Function

Hello again, Mr. Rothstein -

The new UDF still didn't scrub those extra spaces - perhaps I am doing something wrong?

Thanks so much for your time!
 
Upvote 0
Hello again, Mr. Rothstein -

The new UDF still didn't scrub those extra spaces - perhaps I am doing something wrong?
Can you send a copy of your workbook to me so that I can see what my code is doing with your data directly? If so, my email address is...

rick DOT news AT verizon DOT net

Please mention this thread's title in your message so I can relate what you send me to the discussion here.
 
Upvote 0
Can you send a copy of your workbook to me so that I can see what my code is doing with your data directly? If so, my email address is...

rick DOT news AT verizon DOT net

Please mention this thread's title in your message so I can relate what you send me to the discussion here.

Certainly! Just sent it now.

Thank you!
 
Upvote 0
My previous fix turned out to be "silly code" on closer examination. I think this UDF should work better...
Code:
Function NoParens(S As String) As String
  Dim X As Long, Parts() As String
  Const Punctuations As String = """.,:;!?"
  Parts = Split(Replace(S, ")", "("), "(")
  For X = 1 To UBound(Parts) Step 2
    Parts(X) = ""
  Next
  NoParens = Application.Trim(Join(Parts, " "))
  For X = 1 To Len(Punctuations)
    NoParens = Replace(NoParens, " " & Mid(Punctuations, X, 1), Mid(Punctuations, X, 1))
  Next
End Function
Note: I guessed at all the types of punctuations that could follow one of your closing parenthesis characters and encapsulated them in the Punctuations constant (the Const statement)... if you find I have missed any, you can just add it to the back of the list (just be make sure it does not naturally occur in your text with a space before it as that is what I used to identify what needs to be fixed).
 
Upvote 0
It worked!!! I really appreciate you taking time to help me with this and to provide clear, detailed instructions - I can't thank you enough!!!

Have a great day!
 
Upvote 0

Forum statistics

Threads
1,216,222
Messages
6,129,589
Members
449,520
Latest member
TBFrieds

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