Addig specif numbers within one cell

cyberilui

New Member
Joined
Sep 15, 2019
Messages
4
I have an attorney billing template in which I enter data as follows in one cell: Office conference with Blank Client regarding freight damage [1.25]; review documents provided by Blank [1.5]; memo to file re potential case [.5].

I would like a formula or way to have all the numbers inside [x] to be added up automatically. Is this possible?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi & welcome to MrExcel.
How about
Code:
Function cyberilui(St As String) As Double
   Dim Sp As Variant
   Dim i As Long
   Sp = Split(St, "[")
   For i = 0 To UBound(Sp)
      If IsNumeric(Split(Sp(i), "]")(0)) Then cyberilui = cyberilui + Split(Sp(i), "]")(0)
   Next i
End Function
Used like
=cyberilui(A2)
 
Upvote 0
Here is another UDF (user defined function) that you can consider...
Code:
Function BracketSum(St As String) As Double
  Dim V As Variant
  For Each V In Split(St, "[")
    BracketSum = BracketSum + Val(V)
  Next
End Function

HOW TO INSTALL UDFs
------------------------------------
If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use BracketSum just like it was a built-in Excel function. For example,

=BracketSum(A1)

If you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Upvote 0
Thank you, I get the following message "ambiguous name detected: BracketSum"

XLS%20capture.JPG

XLS%20capture.JPG


Here is another UDF (user defined function) that you can consider...
Code:
Function BracketSum(St As String) As Double
  Dim V As Variant
  For Each V In Split(St, "[")
    BracketSum = BracketSum + Val(V)
  Next
End Function

HOW TO INSTALL UDFs
------------------------------------
If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use BracketSum just like it was a built-in Excel function. For example,

=BracketSum(A1)

If you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Upvote 0
That means you have two procedures both with the same name (BracketSum)... VBA does not know which one to use so it issues the error. Remove or comment out one of them (the older one if you want to try the one I recently posted).
 
Upvote 0
OK, I see that I had added two exact modules named BracketSum. I removed all but one and now it works!!!
 
Upvote 0
If your sample is fairly representative. That is, the text in the cell is not too long then this standard worksheet formula may do what you want. Currently it is expecting a maximum of 5 numbers in the cell.

Excel Workbook
AB
1Test [1.25]; other textk [1.5]; m0]",5),""),"]",REPT(" ",255)),255*{1,3,5,7,9},255))]2.75
2Office conference with Blank Client regarding freight damage [1.25]; review documents provided by Blank [1.5]; memo to file re potential case [.5].3.25
3Office conference with Blank Client regarding freight damage [1.25]; review documents provided by Blank [1.5]; memo to file re potential case [.5].Office conference with Blank Client regarding freight damage [1.25]; review documents provided by Blank [1.5]; m6
Sum in brackets
 
Upvote 0
.. & a non-looping udf
Code:
Function BrSum(s As String) As Double
  With CreateObject("VBScript.RegExp")
    .Global = True
    .Pattern = "(^|\])(.*?)(\[|$)"
    BrSum = Evaluate(.Replace(s, "+") & "+0")
  End With
End Function
 
Upvote 0
Every now and then I modify one of the bracketed numbers and I get the following in the sum box "#NAME?

I cannot figure out what caused this or how to fix.

Thanks

That means you have two procedures both with the same name (BracketSum)... VBA does not know which one to use so it issues the error. Remove or comment out one of them (the older one if you want to try the one I recently posted).
 
Upvote 0
That means that Xl cannot find the UDF. Make sure that it's in the workbook you're using it in & that macros are enabled.
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,040
Members
448,543
Latest member
MartinLarkin

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