+ Reply to Thread
Results 1 to 9 of 9

Need to sum above the active cell until bold

Hybrid View

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

    Need to sum above the active cell until bold

    Hi,

    Ive been trying to change the code related to post http://www.excelforum.com/excel-gene...ntil-bold.html in order to sum above the active cell until it hits a bold cell.
    Currently the code sums below the active cell until it finds a bold one.

    Function SumNotBold(rng As Range) As Double
    Dim c As Range, acall As Range
    Set acall = Application.Caller.Offset(1)
    Set funcrng = Intersect(Range(acall, acall.End(xlDown)), rng, Application.Caller.Parent.UsedRange)
    For Each c In funcrng
        If c.Font.Bold = True Then Exit For
        SumNotBold = SumNotBold + IIf(IsNumeric(c), c, 0)
    Next
    End Function
    I've tried changing it to:

    Function SumNotBold(rng As Range) As Double
    Dim c As Range, acall As Range
    Set acall = Application.Caller.Offset(-1)
    Set funcrng = Intersect(Range(acall, acall.End(xlUp)), rng, Application.Caller.Parent.UsedRange)
    For Each c In funcrng
        If c.Font.Bold = True Then Exit For
        SumNotBold = SumNotBold + IIf(IsNumeric(c), c, 0)
    Next
    End Function
    with no success.

    Can anyone help me or explain me where to start?

    Thanks in advance!
    Last edited by alansidman; 10-11-2013 at 10:57 AM. Reason: code tags added.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,732

    Re: Need to sum above the active cell until bold

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (Added this time. Please read the rules and adhere to them.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

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

    Re: Need to sum above the active cell until bold

    Sorry, It will not happen again. Thank you.

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Need to sum above the active cell until bold

    attach please a sample file with data and desired result
    If solved remember to mark Thread as solved

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Need to sum above the active cell until bold

    Hi, elpoder,

    you must alter the logic from going down until a cell is bold to to start from when a cell is bold.

    Maybe try:
    Function SumNotBold(rng As Range) As Double
    Dim c As Range, acall As Range, funcrng As Range, blnAdd As Boolean
    Set acall = Application.Caller.Offset(-1)
    Set funcrng = Range(acall, acall.End(xlUp))
    blnAdd = False
    For Each c In funcrng
        If c.Font.Bold = True Then blnAdd = True
        If blnAdd Then SumNotBold = SumNotBold + IIf(IsNumeric(c), c, 0)
    Next c
    End Function
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

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

    Re: Need to sum above the active cell until bold

    I appreciate the code provided by HaHoBe, but it's still not working.

    I'm attaching the excel sheet for more details. I hope this will be more helpful.

    Thank you!
    Attached Files Attached Files

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Need to sum above the active cell until bold

    Hi, elpoder,

    I hope this will be more helpful.
    Sorry but not for me as I see only a nomal sum function in the cells. Maybe you could just use a different formula like
    Formula: copy to clipboard
    =SUMIF($B$1:C5,B6,$C$1:C5)

    Ciao,
    Holger

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Need to sum above the active cell until bold

    Hi, elpoder,

    the range being used for the sample is like
    Formula: copy to clipboard
    =SumNotBoldUp($C$1:C5)

    for C6 and should be starting with C1 as well for the other cells.

    UDF being used:
    Function SumNotBoldUp(rng As Range) As Double
    Dim aCall As Range
    Dim funcRng As Range
    Dim lngCounter As Long
    
    Set aCall = Application.Caller.Offset(-1)
    Set funcRng = Range(aCall, aCall.End(xlUp))
    
    For lngCounter = funcRng.Cells.Count To 1 Step -1
        With funcRng.Cells(lngCounter)
          If funcRng.Cells(lngCounter).Font.Bold = True Then Exit For
          SumNotBoldUp = SumNotBoldUp + IIf(IsNumeric(.Value), .Value, 0)
        End With
    Next lngCounter
    
    Set funcRng = Nothing
    Set aCall = Nothing
    End Function
    Ciao,
    Holger

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

    Re: Need to sum above the active cell until bold

    Hi Holger,

    I really appreciate your time and excel expertise. It worked out perfectly!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Highlight Active Row macro, and Bold the Active Cell
    By StudentTeacher in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-08-2013, 07:43 PM
  2. [SOLVED] bold font in accordance with active cell
    By marreco in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-07-2013, 08:42 AM
  3. Separating Bold from After-Bold Parts of Cell Strings
    By mlexcelhelpforum in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-19-2012, 07:11 AM
  4. Whole row of active cell should be bold
    By GI30065 in forum Excel General
    Replies: 2
    Last Post: 04-12-2007, 05:15 PM
  5. Join bold and non-bold text in one cell
    By bkincaid in forum Excel General
    Replies: 3
    Last Post: 03-20-2006, 09:10 PM

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