Re: counting by color by Harald
Harald
Wed Jul 23 05:41:28 CDT 2008
I've found it more user friendly to use "same color as this cell" instead of
hardcoding an obscure indexnumber, like
Function SumByColor(InRange As Range, SameColorAs As Range, _
Optional OfText As Boolean = False) As Double
Dim WhatColorIndex As Integer
If OfText = True then
WhatColorIndex = SameColorAs(1).Font.ColorIndex
Else
WhatColorIndex = SameColorAs(1).Interior.ColorIndex
...
(Haven't done this yet with 2007 though, so I'm not sure how it deals with
all variations of themes, pallettes and all that stuff, or if there's
another better approach.)
Best wishes Harald
"JE McGimpsey" <jemcgimpsey@mvps.org> wrote in message
news:jemcgimpsey-B3D862.22394422072008@news.microsoft.com...
> One minor caveat -
>
> This is really "SumByColorIndex", not SumByColor.
>
> ColorIndex 3 in the default palette is red, and ColorIndex 6 in the
> default palette is yellow
>
> However, the color assignments may not hold true if the Color Palette
> has been modified (e.g., manually, or by applying a different theme).
>
> If one's users never change themes or color palette settings, that
> shouldn't be a problem.
>
>
>
> In article <59669047-1B33-4A1A-B9B2-CB9CCFEAA445@microsoft.com>,
> OssieMac <OssieMac@discussions.microsoft.com> wrote:
>
>> The function works.
>>
>> For background (or interior color) red which is colorindex 3, you need to
>> enter the formula as:-
>> =SumByColor(A1:A14,3,FALSE)
>>
>> The FALSE is optional when summing by background. You could use:-
>> =SumByColor(A1:A14,3)
>>
>>
>> For font color yellow which is colorindex 6, the formula is a follows:-
>> =SumByColor(A1:A14,6,TRUE). (TRUE is not optional here because that is
>> what
>> tells the system that it is the font color and not the background color
>> to
>> look for.
>>