Results 1 to 10 of 10

Thread: Addig specif numbers within one cell
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Sep 2019
    Posts
    4
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Addig specif numbers within one cell

    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?

  2. #2
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,190
    Post Thanks / Like
    Mentioned
    470 Post(s)
    Tagged
    47 Thread(s)

    Default Re: Addig specif numbers within one cell

    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)
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  3. #3
    MrExcel MVP Rick Rothstein's Avatar
    Join Date
    Apr 2011
    Location
    New Jersey, USA
    Posts
    35,244
    Post Thanks / Like
    Mentioned
    92 Post(s)
    Tagged
    33 Thread(s)

    Default Re: Addig specif numbers within one cell

    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.
    Rick's "mini" blog... http://www.excelfox.com/forum/f22/
    .
    Want to post a small screen shot? See Part B here.

  4. #4
    New Member
    Join Date
    Sep 2019
    Posts
    4
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Addig specif numbers within one cell

    Thank you, I get the following message "ambiguous name detected: BracketSum"




    Quote Originally Posted by Rick Rothstein View Post
    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.

  5. #5
    MrExcel MVP Rick Rothstein's Avatar
    Join Date
    Apr 2011
    Location
    New Jersey, USA
    Posts
    35,244
    Post Thanks / Like
    Mentioned
    92 Post(s)
    Tagged
    33 Thread(s)

    Default Re: Addig specif numbers within one cell

    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).
    Rick's "mini" blog... http://www.excelfox.com/forum/f22/
    .
    Want to post a small screen shot? See Part B here.

  6. #6
    New Member
    Join Date
    Sep 2019
    Posts
    4
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Addig specif numbers within one cell

    OK, I see that I had added two exact modules named BracketSum. I removed all but one and now it works!!!

  7. #7
    MrExcel MVP
    Moderator
    Peter_SSs's Avatar
    Join Date
    May 2005
    Location
    Macksville, Australia
    Posts
    40,976
    Post Thanks / Like
    Mentioned
    90 Post(s)
    Tagged
    21 Thread(s)

    Default Re: Addig specif numbers within one cell

    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.

    Sum in brackets

    AB
    1Test [1.25]; other textk [1.5]; m2.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

    Spreadsheet Formulas
    CellFormula
    B1=SUMPRODUCT(0+MID(SUBSTITUTE(SUBSTITUTE(A1&REPT("]0]",5),"[","]"),"]",REPT(" ",255)),255*{1,3,5,7,9},255))


    Excel tables to the web >> Excel Jeanie HTML 4
    Hope this helps, good luck.
    Peter
    Excel 365 - Windows 10
    - Want to help your helpers by posting a small, copyable, screen shot directly in your post? Look here
    - If posting vba code, please use Code Tags - like this [code]Paste code here[/code] - or use the # key in the Reply window
    - Read: Forum Rules, Forum Use Guidelines, & FAQ

  8. #8
    MrExcel MVP
    Moderator
    Peter_SSs's Avatar
    Join Date
    May 2005
    Location
    Macksville, Australia
    Posts
    40,976
    Post Thanks / Like
    Mentioned
    90 Post(s)
    Tagged
    21 Thread(s)

    Default Re: Addig specif numbers within one cell

    .. & 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
    Hope this helps, good luck.
    Peter
    Excel 365 - Windows 10
    - Want to help your helpers by posting a small, copyable, screen shot directly in your post? Look here
    - If posting vba code, please use Code Tags - like this [code]Paste code here[/code] - or use the # key in the Reply window
    - Read: Forum Rules, Forum Use Guidelines, & FAQ

  9. #9
    New Member
    Join Date
    Sep 2019
    Posts
    4
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Addig specif numbers within one cell

    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

    Quote Originally Posted by Rick Rothstein View Post
    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).

  10. #10
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,190
    Post Thanks / Like
    Mentioned
    470 Post(s)
    Tagged
    47 Thread(s)

    Default Re: Addig specif numbers within one cell

    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.
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •