Home |
Search |
Today's Posts |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() "Murph" wrote in message ... I am using the following Macro - the formula I use to access the macro is =sumBYCOLOR(C13:H22,3,TRUE) The problem I am having is that the formula does not automatically calculate no information inputted into the excel sheet. I have to go to the cell with the formula and place my cursor at the end of the formula and hit enter for it to adjust with the new information. Any help? Macro is:Function SumByColor(InRange As Range, WhatColorIndex As Integer, _ Optional OfText As Boolean = False) As Double ' ' This function return the SUM of the values of cells in ' InRange with a background color, or if OfText is True a ' font color, equal to WhatColorIndex. ' Dim Rng As Range Dim OK As Boolean Application.Volatile True For Each Rng In InRange.Cells If OfText = True Then OK = (Rng.Font.ColorIndex = WhatColorIndex) Else OK = (Rng.Interior.ColorIndex = WhatColorIndex) End If If OK And IsNumeric(Rng.Value) Then SumByColor = SumByColor + Rng.Value End If Next Rng End Function I modified the code a bit so a user can select the color by incduing a cell range reference: Function SumByColor(InRange As Range, rColor As Range, _ Optional OfText As Boolean = False) As Double ' ' This function return the SUM of the values of cells in ' InRange with a background color, or if OfText is True a ' font color, equal to WhatColorIndex. ' ' the user can select the color by including a reference to a call or a range of cells ' of the appropriate color Dim Rng As Range Dim iClr As Integer ' the color to sum Dim iCellClr ' the color of the cell Dim OK As Boolean Application.Volatile True If OfText = True Then iClr = rColor.Font.ColorIndex Else iClr = rColor.Interior.ColorIndex End If For Each Rng In InRange.Cells If OfText = True Then iCellClr = Rng.Font.ColorIndex Else iCellClr = Rng.Interior.ColorIndex End If If IsNumeric(Rng.Value) And iCellClr = iClr Then SumByColor = SumByColor + Rng.Value End If Next Rng Application.Calculate End Function Comments? |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
SumByColor & #NAME? | Excel Worksheet Functions | |||
sumbycolor formula | Excel Worksheet Functions | |||
SumByColor Stopped Working | Excel Worksheet Functions | |||
how to use sumbycolor fuction? | Excel Worksheet Functions | |||
Start Macro / Stop Macro / Restart Macro | Excel Programming |