+ Reply to Thread
Results 1 to 6 of 6

need a U.D.F to sum up cells highlighted Red

Hybrid View

  1. #1
    Registered User
    Join Date
    01-26-2014
    Location
    Sydney
    MS-Off Ver
    Excel 2013
    Posts
    93

    need a U.D.F to sum up cells highlighted Red

    Hi

    I have a cell range C4:W40 which has values.Cells highlighted RED i need a User defined Function to sum up all values in RED cells.

    I am very limited in VBA but appreciate a code if possible

    Thanks
    Last edited by James__S; 04-16-2014 at 11:24 AM.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: u.d.f

    If the cells are highlighted red as part of conditional formatting, it can be very challenging. If you are the one that applied the color for each individual cell then this should work:

    Function CountReds(myRange As Range)
    Dim rCell As Range
    Dim Count As Long
    
    Count = 0
    
    For Each rCell In myRange
        If rCell.Interior.ColorIndex = 3 Then 'red
            Count = Count + rCell.Value
        End If
    Next rCell
    
    CountReds = Count
    
    End Function
    In a cell put "=CountReds(C4:W40)"
    Last edited by stnkynts; 04-16-2014 at 10:24 AM.

  3. #3
    Valued Forum Contributor adyteo's Avatar
    Join Date
    01-10-2013
    Location
    Calgary
    MS-Off Ver
    Excel 2010
    Posts
    540

    Re: u.d.f

    this is the function (add it to a Module)
    
    Function SumIfRed(rRange As Range)
    Dim cell
    
    SumIfRed = 0
    For Each cell In rRange
        If cell.Interior.ColorIndex = 3 Then SumIfRed = SumIfRed + cell.Value
    Next
    
    End Function
    then, in a cell, type =SumIfRed(here select the range of cells) then press enter
    Click on the star if you think I helped you

  4. #4
    Registered User
    Join Date
    01-26-2014
    Location
    Sydney
    MS-Off Ver
    Excel 2013
    Posts
    93

    Re: need a U.D.F to sum up cells highlighted Red

    Title changed:apologies

    the cells are highlighted RED through C.F...both functions return 0

    Thanks

  5. #5
    Registered User
    Join Date
    01-26-2014
    Location
    Sydney
    MS-Off Ver
    Excel 2013
    Posts
    93

    Re: need a U.D.F to sum up cells highlighted Red

    I just changed the color of the cell manually and they work....is it not possible to sum if C.F used to color cells?

    Thanks

  6. #6
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: need a U.D.F to sum up cells highlighted Red

    Its not impossible just time consuming. So much so that I doubt anyone here will want to do it. Here is some information on how to do this kind of thing

    http://www.cpearson.com/excel/cfcolors.htm

    Best of luck.

+ 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