I have a UDF that will look in a given cell for numbers inside of parenthesis then sum all numbers inside of parenthesis in a given cell, it works well 90% of the time but when I have something inside of parenthesis that is not a number i.e a word or phrase, it will return #VALUE! I'm trying to fix this so that it will ignore words etc that are inside parenthesis. Also for some reason, having a "." after parenthesis makes it so that the numbers in the parenthesis before the "." are ignored when they shouldn't be.
screenshot of problems explained above
The function is as follows
Public Function Addum(rng As Range) As Double
Dim s As String, L As Long, temp As String
Dim CH As String
s = rng.Value
L = Len(s)
For i = 1 To L
CH = Mid(s, i, 1)
If CH Like "[0-9]" Or CH = "." Or CH = "(" Or CH = ")" Then
temp = temp & CH
Else
temp = temp & " "
End If
Next i
temp = Application.WorksheetFunction.Trim(temp)
arr = Split(temp, " ")
For Each a In arr
If Left(a, 1) = "(" Then
a = Mid(a, 2, Len(a) - 2)
If IsNumeric(a) Then
Addum = Addum + CDbl(a)
End If
End If
Next a
End Function
this question is different from Excel: Sum numbers inside a text block in a cell because im asking for it to work when there are words inside of parenthesis present and when there are "." after the parenthesis.
thanks in advance for any help that you can provide!