+ Reply to Thread
Results 1 to 27 of 27

Function to sum until bold

  1. #1
    Registered User
    Join Date
    07-11-2012
    Location
    Hamilton, New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    25

    Function to sum until bold

    Hi!

    Ive been trying to find a solution to this but cant seem to find it. Can I create a function that will sum until it hits another bold cell? I have a header column that sums down all the values in its category and displays the total in bold. (There are multiple categories each having a different varying number of rows) I do it manually now but I'd like to do it automatically to just sum the numbers in that column until it reaches a bold number. Can anyone help me or tell me where to start?

  2. #2
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Function to sum until bold

    There are no conventional methods that would achieve this.

    While it is theoretically possible to do, it would be borderline impossible without seeing the layout of your sheet.

    Are there any other factors that could be used as an identifier?

    From your description of your problem, it sounds like you need SUMIF() with category as criteria. A sample sheet would help.

  3. #3
    Registered User
    Join Date
    07-11-2012
    Location
    Hamilton, New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Function to sum until bold

    Im not sure what you mean if there are other factors. i created a function in vba that "sums if bold"(cell H16, it doesnt work because i copied it to a new sheet) to get the totals. but now i want to automatically create those bold totals by summing down until it hits a new category, or bold numberSample Sheet.xlsx

  4. #4
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Function to sum until bold

    Quote Originally Posted by biancam View Post
    Im not sure what you mean if there are other factors.
    Anything else in the bold rows that could be used to identify them, in your sample there is, only the rows you want to sum have 1 entered in column A, so you could use a conventional formula.

    =SUMIF($A:$A,1,H:H)

  5. #5
    Registered User
    Join Date
    07-11-2012
    Location
    Hamilton, New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Function to sum until bold

    Its not working for me, the 1's will be different, there really is no other factors as an identifier, it will be different every time.

    I would like cell H7 (the Material Only Total box ) to sum cells H8:H10 (which will be a different number of rows each time) and will be bolded. since there are no identifying factors i thought it could be identified by whether the number was bold or not.

    Hope this makes sense.

  6. #6
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Function to sum until bold

    Going back to your earlier post

    Quote Originally Posted by biancam View Post
    i created a function in vba that "sums if bold"(cell H16, it doesnt work because i copied it to a new sheet)
    Do you mean that the formula is in a different sheet to the bold cells, of that you're copying everything to a new workbook that doesn't have the code?

    Please post the code, it was missing from your sample workbook.

  7. #7
    Registered User
    Join Date
    07-11-2012
    Location
    Hamilton, New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Function to sum until bold

    That formula is in the same sheet summing those bold cells Im trying to make now.

    I didnt post it because I don't think its really relevant to what I'm trying to do but here it is:


    Function SumIfBold(MyRange As Range) As Double

    Dim cell As Range
    For Each cell In MyRange
    If cell.Font.Bold = True Then
    SumIfBold = SumIfBold + cell
    End If
    Next cell

    End Function

  8. #8
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Function to sum until bold

    So why don't you just add the code to the new workbook?

    You're not going to be able to this without vba unless you can find a common value or identifier in the rows, standard excel functions cannot identify cell formats.

  9. #9
    Registered User
    Join Date
    07-11-2012
    Location
    Hamilton, New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Function to sum until bold

    Im not sure you understand what Im trying to do. The function i posted before was to sum the cells that are bold. right now, in a completely different cell im trying to sum the cells below it until it reaches a bold cell. using vba is fine I just dont know how to write it, I thought i would use an offset but im not sure.

  10. #10
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Function to sum until bold

    You're right, I was missing the point of your question.

    Without vba, enter this formula into H7 and Array confirm with Shift Ctrl Enter, then copy the cell, not the formula, and paste as required.

    =SUM(H8:INDEX(H8:H$1000,MATCH(TRUE,ISBLANK($F8:$F$1000),0)-1))

    Naturally, with vba the formula will be less complex, as soon as I have it working I'll post the code.

  11. #11
    Registered User
    Join Date
    07-11-2012
    Location
    Hamilton, New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Function to sum until bold

    I have no idea what you did, but it works!!! this is perfect, thanks

  12. #12
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Function to sum until bold

    As promised, the vba version

    The code
    Please Login or Register  to view this content.
    The formula

    =SumNotBold(H:H)

    You don't need to enter rows in the formula, the function will find them.

  13. #13
    Registered User
    Join Date
    07-11-2012
    Location
    Hamilton, New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Function to sum until bold

    Looks good, i cant get the code to work correctly though. it keeps giving me #VALUE! I dont have to select a range? because I have merged cells and words further down in the sheet. Im not sure what it could be

  14. #14
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Function to sum until bold

    How about in H16
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    And in J16
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  15. #15
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Function to sum until bold

    You need to enter a range as columns, i.e. H:H

    You don't need to include rows in the range, but the function should accept it if you want to test with a smaller range.

    The text will not cause problems unless it's between the cell with the formula and the next cell with a bold font.

    Merged cells will cause problems, I'll edit the to ignore them.

  16. #16
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Function to sum until bold

    Can you post a sample sheet with merged cells and text to match your main sheet layout, the only time I get an error is when there is nothing to sum below the cell with the formula.

  17. #17
    Registered User
    Join Date
    07-11-2012
    Location
    Hamilton, New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Function to sum until bold

    I cant change H16 and J16 to those manual divisions because I usually have more than two items. in the sample sheet when i get rid of sum if bold it works. when i leave it in it gives me a circular reference.

    when i copied the code to the whole workbook it works but only for one location. Im attaching the whole sheet. I hope this will be more helpful
    Attached Files Attached Files

  18. #18
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Function to sum until bold

    It's the formula that return blanks causing the problems, this fixes it.

    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    07-11-2012
    Location
    Hamilton, New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Function to sum until bold

    WORKS!!! thanks so much

  20. #20
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Function to sum until bold

    Why not try this? No need for VBa UDFs!

    In D19, Drag accross to S19
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  21. #21
    Registered User
    Join Date
    07-11-2012
    Location
    Hamilton, New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Function to sum until bold

    That works too! I think the vba is a little cleaner, since I'm not the only one using the sheet but is there any other advantages to not using vba?

  22. #22
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Function to sum until bold

    is there any other advantages to not using vba?
    LOL, there's a debate that's been going on for years. Since you are the only one using the workbook, probably not. In general, you don't need to worry about enabling formulas on opening. I think it's usually easier to see exactly what's happening with a formula, especially with "Evaluate Formula" rather than stepping through code. It really comes down to personal preference. Oh and the formula approach might be a few microseconds faster.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  23. #23
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Function to sum until bold

    Best to avoid VBa whenever possible.

    1/. Many companies still don't allow macros.
    2/. Some versions of Excel don't support VBa
    3/. If the workbook is opened with macros disabled, the UDFs will obviously fail, and the sheet is rendered useless.
    4/. On balance VBa is slower than native formula. On small workbooks this really doesn't matter.
    5/. Hard coded VBa is usually less portable than native formulae, this is dependent on the coders skills.
    6/. etc, etc ......

    If you are worried about users accidentally deleting, changing formulae, lock the cells and protect the sheet.

  24. #24
    Registered User
    Join Date
    07-11-2012
    Location
    Hamilton, New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Function to sum until bold

    Cool, thanks everyone!

  25. #25
    Registered User
    Join Date
    07-24-2009
    Location
    mexico
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Function to sum until bold

    Hi,

    I tried this code and it worked out perfectly.
    I wonder how it can sum above the active cell.
    I did some changes with no success.

    Best Regards,

  26. #26
    Registered User
    Join Date
    08-21-2015
    Location
    south africa
    MS-Off Ver
    2013
    Posts
    5

    Re: Function to sum until bold

    Hi,

    im new here.

    Can anyone help to get this sample file to sum up just the blue rows.

    I've used autosum to get the first cell [H2] but I would like to get a formula going [not vba] to automate this for future use.

    Autosum requires me to manually select the cells hence the request.

    I have tried to implement what has been suggested already on this thread but my excel skills are terrible.

    Please advise.

    Thanks in advance.
    Attached Files Attached Files

  27. #27
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Function to sum until bold

    Hi faqir41.

    Unfortunately I can't answer your question for you here because your post does not comply with the forum rules.

    2. Don't post a question in the thread of another member -- start your own. If you feel it's particularly relevant, provide a link to the other thread. You may include up to 3 links to other URLs in a single post, no more, so only link to the relevant pages.
    In addition to being a requirement of the rules, a new thread (when appropriate) will get more attention from people than an old thread so you're more likely to get your question answered.

    I would suggest a quick read of the forum rules before posting.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1