View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
ShaneDevenshire ShaneDevenshire is offline
external usenet poster
 
Posts: 2,344
Default create a formula based on cell color

Hi,

Add the following VBA code to a module in the Visual Basic Editor of your
workbook:

Function CountOfColors(myRange As Range, myCell As Range) As Long
Dim Counter As Integer
Dim cell As Range
Counter = 0
For Each cell In myRange
If cell.Interior.ColorIndex = myCell.Interior.ColorIndex Then
Counter = Counter + 1
End If
Next cell
CountOfColors = 25 * Counter
End Function

Suppose that the cells that you want to check are in the range A1:D10, then
in a cell outside this range color one of the cells whatever color the cells
are that you want to find, in your example some shade of yellow. Suppose
that the cell you color is F1, then you can enter the following formula in a
cell:

=countofcolors(A1:D10,F1)

The beauty of this function is that it can work for any color.

--
Cheers,
Shane Devenshire


"pcwolfie" wrote:

Hi,

I was wondering if there was a formula to add up cells based on the cell
color? These cells have names in them and no numbers

For example:

Column A Column B
white cell yellow cell
white cell white cell
yellow cell yellow cell

I need the cells that are yellow to equal 25 and the cells with no color to
equal 45.

This spreadsheet is to total the pay for about 100 people and the yellow
cells are not all in a column.

Is there a formula along the lines of: if a person's name is in a yellow
cell, then the dollar amount associated with the cell = 25

Sorry this is so long, I wasn't sure how else to explain it.

Thanks for the help,

Laura