+ Reply to Thread
Results 1 to 4 of 4

sum by color

  1. #1
    Registered User
    Join Date
    02-22-2013
    Location
    india
    MS-Off Ver
    2010
    Posts
    4

    sum by color

    sir, I have one macro code to sum by color, but the problem is that the code does not auto change the total when the color changes. the code is as follows :

    Function SumIFbyColor(rColor As Range, rCells As Range)
    'Parameter rColor is used for a cell from your worksheet
    'formatted with the same color like color desired from the table.
    'Parameter rCells is used for a cell range from your worksheet
    'that can contain cells formatted with the same color of font or background
    'like referenced cell.

    'Defining variables
    Dim rRange As Range
    Dim sumColor As Long


    'Initiating sumColor
    sumColor = 0


    ' Parsing cells from range
    For Each rRange In rCells
    If rRange.Font.Color = rColor.Font.Color Or rRange.Interior.Color = rColor.Interior.Color Then
    sumColor = sumColor + rRange.Cells.Value
    End If
    Next rRange

    ' Return results
    SumIFbyColor = sumColor

    End Function

    can you make it to auto change ?

    Thanks

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: sum by color

    force a recalc activesheet.calculate, on the Worksheet_change event, not sure if making it volatile, application.volatile, would be triggered off a re-format.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: sum by color

    There is no way to make it automatically recalculate when you manually format a cell to change color. Color is not data to Excel.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    02-22-2013
    Location
    india
    MS-Off Ver
    2010
    Posts
    4

    Re: sum by color

    @nathansav



    i am new to macros, I don't know how to edit this one......

    can u please edit the above macro ?

+ 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