Finding value between parentheses

gittar29

New Member
Joined
Jun 17, 2003
Messages
29
I am trying to write a string formula which will look a code between parentheses.

My logic is this:

Search for the first parentheses, find the last parentheses, and return everything in between. Im sure there is a string function, but not exactly sure which one will do the trick. And by the way, the code in between the parentheses varies from length 3 to 9.

Thanks.
 
I mean I am using this formula:

Function SumParens(S As String) As Variant
Dim X As Long, Parts() As String
If Len(S) Then
Parts = Split(Replace(S, ")", "("), "(")
For X = 1 To UBound(Parts)
SumParens = SumParens + Val(Parts(X))
Next
Else
SumParens = ""
End If
End Function
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi
Welcome to the board

Why a udf? It seems a formula will do it. For ex.:

=SUMPRODUCT(--MID(E2:E4,FIND("(",E2:E4)+1,FIND(")",E2:E4)-FIND("(",E2:E4)-1))
 
Upvote 0
I tried the formula you have provided above and it gave an error; not sure what to do.

The UDF seems to work for me but only for one row.

Either way will work as long as I can get a sum for multiple rows.

thanks for all your help.
 
Upvote 0
I tried the formula you have provided above and it gave an error;..
1. What error?

2. Do you have any
- blank cells in the range or
- any cells other cells that do not contain a number enclosed between the first opening parenthesis and the first closing parenthesis?


If so, perhaps try this modification.

=SUMPRODUCT(--MID(E2:E4&"(0)",FIND("(",E2:E4&"(")+1,FIND(")",E2:E4&"(0)")-FIND("(",E2:E4&"(")-1))

If this still doesn't work, please give a small set of sample data for which it fails.
 
Upvote 0

Forum statistics

Threads
1,216,042
Messages
6,128,467
Members
449,455
Latest member
jesski

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