Sum Highlighted Cells
Here are 2 custom formulas that will work for you. The first one uses a
named range called "MyData" the other formula does exactly the same thing as
the first, only you provide the cell address when you enter the formula into
the spreadsheet.
CalcYellowDogCellRedux(A1:X100)
interior color index of 6 is yellow..
----------------------------------------------------------------------
Function CalcYellowDogCells() As Double
Dim wb As Workbook
Dim ws As Worksheet
Dim r As Range
Dim dblSum As Double
Dim l As Long
Application.Volatile
Set wb = ActiveWorkbook
Set ws = wb.Worksheets("Sheet1")
ws.Activate
Set r = Range("MyData")
For l = 1 To r.Cells.Count
If r.Cells(l).Interior.ColorIndex = 6 Then
dblSum = dblSum + r.Cells(l).Value
End If
Next l
Set wb = Nothing
Set ws = Nothing
Set r = Nothing
CalcYellowDogCells = dblSum
Exit Function
End Function
----------------------------------------------------------------------
Function CalcYellowDogCellsRedux(CellAddresses As Range) As Double
Dim wb As Workbook
Dim ws As Worksheet
Dim r As Range
Dim dblSum As Double
Dim l As Long
Application.Volatile
Set wb = ActiveWorkbook
Set ws = wb.Worksheets("Sheet1")
ws.Activate
Set r = CellAddresses
For l = 1 To r.Cells.Count
If r.Cells(l).Interior.ColorIndex = 6 Then
dblSum = dblSum + r.Cells(l).Value
End If
Next l
Set wb = Nothing
Set ws = Nothing
Set r = Nothing
CalcYellowDogCellsRedux = dblSum
Exit Function
End Function
----------------------------------------------------------------------
--
Kevin Backmann
"Jenny" wrote:
I have highlighted cells within a spreadsheet by changing the box color to
yellow. Is there anyway to easily create a formula to SUM these cells for
me? Thanks
|