M
Michael Purcell
I found Chris Pearson's CountByColor function which lets me do exactly
what I want to do. I'm using the function in Excel 2000 on Win98SE.
When I call the function on a worksheet, it causes the save dialog to
appear when the workbook closes, even though there is no new data to
save (for example, open and immediately close the workbook). The save
dialog does not appear when the function call is removed from the
worksheet.
I created a module in the workbook and copied the following code to
the module:
Function CountByColor(InRange As Range, WhatColorIndex _
As Integer, Optional OfText As Boolean = False) As Long
'
' This function returns 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
It doesn't make sense to me that this function will cause this
problem. Appearantly, a flag is getting set somewhere, but I don't
know what to do to solve the problem so that I can use the code.
TIA for your help,
Michael Purcell
what I want to do. I'm using the function in Excel 2000 on Win98SE.
When I call the function on a worksheet, it causes the save dialog to
appear when the workbook closes, even though there is no new data to
save (for example, open and immediately close the workbook). The save
dialog does not appear when the function call is removed from the
worksheet.
I created a module in the workbook and copied the following code to
the module:
Function CountByColor(InRange As Range, WhatColorIndex _
As Integer, Optional OfText As Boolean = False) As Long
'
' This function returns 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
It doesn't make sense to me that this function will cause this
problem. Appearantly, a flag is getting set somewhere, but I don't
know what to do to solve the problem so that I can use the code.
TIA for your help,
Michael Purcell