Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Jenny
 
Posts: n/a
Default Sum Highlighted Cells

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
  #2   Report Post  
Posted to microsoft.public.excel.misc
Toppers
 
Posts: n/a
Default Sum Highlighted Cells

This is code from Chip Pearson's site which sums cells with a given backgound
colour
or font.

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

You can call this function from a worksheet cell with a formula like
=SUMBYCOLOR(A1:A10,3,FALSE) <==Background colour 3

=SUMBYCOLOR(A1:A10,3,TRUE) <== Font colour 3

HTH

"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

  #3   Report Post  
Posted to microsoft.public.excel.misc
Kevin B
 
Posts: n/a
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips
 
Posts: n/a
Default Sum Highlighted Cells

See http://www.xldynamic.com/source/xld.ColourCounter.html for a working
solution

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Jenny" wrote in message
...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I protect only the highlighted cells in Excel? John White Excel Discussion (Misc queries) 1 December 7th 05 06:57 PM
How do I count cells that have are highlighted a certain color? NicoleE Excel Worksheet Functions 1 September 2nd 05 09:14 PM
Can I sum only highlighted cells in a worksheet? Mr Harlow Excel Worksheet Functions 2 August 29th 05 11:16 PM
Help adding text values Texas-DC_271 Excel Worksheet Functions 7 January 15th 05 11:14 PM
Convert data type of cells to Text,Number,Date and Time Kevin Excel Worksheet Functions 1 December 31st 04 12:57 PM


All times are GMT +1. The time now is 03:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"