F
Francis Hookam
Tom Stiller rightly pointed out
"You're counting color occurrences of color '3' when you seem to be
interested in occurrences of color '36'."
but still I cannot make sense of it which is why I wrote the following - I
should be grateful if someone can help
Thanks (JE McGimpsey) for - http://cpearson.com/excel/colors.htm set out
below,
but I don¹t know enough to understand how to implement it
- I have tried pasting the function into
Workbook1 - This Workbook(Code)
adding
DIM WhatColorIndex as integer
and
WhatColorIndex = 36 ŒLight Yellow
and pasting
=COUNTBYCOLOR(A1:A10,3,FALSE)
into A11
with some of the cells in A1:A10 coloured Light Yellow
but I have obviously got something wrong - clearly I do not understand the
use of functions (after all these years!)
As always your help will is much appreciated
Francis Hookham
==========================================================
Function CountByColor(InRange As Range, _
WhatColorIndex As Integer, _
Optional OfText As Boolean = False) As Long
'
' This function return the number of cells in InRange with
' a background color, or if OfText is True a font color,
' equal to WhatColorIndex.
'
Dim Rng As Range
Application.Volatile True
For Each Rng In InRange.Cells
If OfText = True Then
CountByColor = CountByColor - _
(Rng.Font.ColorIndex = WhatColorIndex)
Else
CountByColor = CountByColor - _
(Rng.Interior.ColorIndex = WhatColorIndex)
End If
Next Rng
End Function
"You're counting color occurrences of color '3' when you seem to be
interested in occurrences of color '36'."
but still I cannot make sense of it which is why I wrote the following - I
should be grateful if someone can help
Thanks (JE McGimpsey) for - http://cpearson.com/excel/colors.htm set out
below,
but I don¹t know enough to understand how to implement it
- I have tried pasting the function into
Workbook1 - This Workbook(Code)
adding
DIM WhatColorIndex as integer
and
WhatColorIndex = 36 ŒLight Yellow
and pasting
=COUNTBYCOLOR(A1:A10,3,FALSE)
into A11
with some of the cells in A1:A10 coloured Light Yellow
but I have obviously got something wrong - clearly I do not understand the
use of functions (after all these years!)
As always your help will is much appreciated
Francis Hookham
==========================================================
Function CountByColor(InRange As Range, _
WhatColorIndex As Integer, _
Optional OfText As Boolean = False) As Long
'
' This function return the number of cells in InRange with
' a background color, or if OfText is True a font color,
' equal to WhatColorIndex.
'
Dim Rng As Range
Application.Volatile True
For Each Rng In InRange.Cells
If OfText = True Then
CountByColor = CountByColor - _
(Rng.Font.ColorIndex = WhatColorIndex)
Else
CountByColor = CountByColor - _
(Rng.Interior.ColorIndex = WhatColorIndex)
End If
Next Rng
End Function