how to add excel calc to this function

rcr1991

New Member
Joined
Oct 26, 2005
Messages
37
A memer turned me on to this fxn, which works perfectly to sum values in cells with a certain internal color.

My problem is I cannot figure out how to use the stdev (standard deviation) function on the same range that is used for the sum. Suggestions?

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
(Source: http://www.cpearson.com/excel/colors.htm)
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try:

Code:
Function SDByColor(InRange As Range, WhatColorIndex As Integer, _
    Optional OfText As Boolean = False) As Double
    Dim Cell As Range
    Dim OK As Boolean
    Dim i As Long
    Dim Rng As Range
    Application.Volatile True
    i = 1
    For Each Cell In InRange.Cells
        If OfText = True Then
            OK = (Cell.Font.ColorIndex = WhatColorIndex)
        Else
            OK = (Cell.Interior.ColorIndex = WhatColorIndex)
        End If
        If OK And IsNumeric(Cell.Value) Then
            If i = 1 Then
                Set Rng = Cell
            Else
                Set Rng = Union(Rng, Cell)
            End If
            i = i + 1
        End If
    Next Cell
    If Not Rng Is Nothing Then
        SDByColor = WorksheetFunction.StDev(Rng)
    End If
End Function
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,730
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top