Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Counting a colour that is Conditionally Formatted

I have a grid that conditionally formats the background colour to Green,
Red or White depending on a criteria. I want to count the number of
times green appears in a row. I've tried modifying the CountByColor
Function but to no avail.

Is this possible?

TIA

Jon

Function CountByColor(InputRange As Range, ColorRange As Range) As Long
Dim cl As Range, TempCount As Long, ColorIndex As Integer
ColorIndex = ColorRange.Cells(1, 1).Interior.ColorIndex
TempCount = 0
For Each cl In InputRange.Cells
If cl.Font.ColorIndex = ColorIndex Then TempCount = TempCount +
1
Next cl
Set cl = Nothing
CountByColor = TempCount
End Function

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default Counting a colour that is Conditionally Formatted

On Sat, 08 Nov 2003 14:14:52 -0500, Crash <[email deleted] wrote:

I have a grid that conditionally formats the background colour to Green,
Red or White depending on a criteria. I want to count the number of
times green appears in a row. I've tried modifying the CountByColor
Function but to no avail.

Is this possible?

TIA

Jon

Function CountByColor(InputRange As Range, ColorRange As Range) As Long
Dim cl As Range, TempCount As Long, ColorIndex As Integer
ColorIndex = ColorRange.Cells(1, 1).Interior.ColorIndex
TempCount = 0
For Each cl In InputRange.Cells
If cl.Font.ColorIndex = ColorIndex Then TempCount = TempCount +
1
Next cl
Set cl = Nothing
CountByColor = TempCount
End Function


How about a Select Case that looks at the formula or the value? If it
can be expressed as an Excel formula, it can be expressed in VBA code.
--
auric "underscore" "underscore" "at" hotmail "dot" com
*****
Don't question authority, he doesn't know either.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Counting a colour that is Conditionally Formatted

Conditional formatting doesn't return a value you can check on directly.
See Chip Pearson's site for an explanation and code:

http://www.cpearson.com/excel/CFColors.htm

--
Regards,
Tom Ogilvy

Crash wrote in message
...
I have a grid that conditionally formats the background colour to Green,
Red or White depending on a criteria. I want to count the number of
times green appears in a row. I've tried modifying the CountByColor
Function but to no avail.

Is this possible?

TIA

Jon

Function CountByColor(InputRange As Range, ColorRange As Range) As Long
Dim cl As Range, TempCount As Long, ColorIndex As Integer
ColorIndex = ColorRange.Cells(1, 1).Interior.ColorIndex
TempCount = 0
For Each cl In InputRange.Cells
If cl.Font.ColorIndex = ColorIndex Then TempCount = TempCount +
1
Next cl
Set cl = Nothing
CountByColor = TempCount
End Function



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Counting a colour that is Conditionally Formatted

On Sat, 08 Nov 2003 14:14:52 -0500, Crash wrote:

I have a grid that conditionally formats the background colour to Green,
Red or White depending on a criteria. I want to count the number of
times green appears in a row. I've tried modifying the CountByColor
Function but to no avail.

Is this possible?

TIA

Jon


I do not believe so. You would need your code to check for the *condition*
that produces the Green result.


--ron
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Counting a colour that is Conditionally Formatted

Thanks Tom, unfortunately the addresses are all relative so Chip's functions
didn't work for me, I ended-up writing a macro to loop through the rows
comparing each column to the master.

Jon

Tom Ogilvy wrote:

Conditional formatting doesn't return a value you can check on directly.
See Chip Pearson's site for an explanation and code:

http://www.cpearson.com/excel/CFColors.htm

--
Regards,
Tom Ogilvy

Crash wrote in message
...
I have a grid that conditionally formats the background colour to Green,
Red or White depending on a criteria. I want to count the number of
times green appears in a row. I've tried modifying the CountByColor
Function but to no avail.

Is this possible?

TIA

Jon

Function CountByColor(InputRange As Range, ColorRange As Range) As Long
Dim cl As Range, TempCount As Long, ColorIndex As Integer
ColorIndex = ColorRange.Cells(1, 1).Interior.ColorIndex
TempCount = 0
For Each cl In InputRange.Cells
If cl.Font.ColorIndex = ColorIndex Then TempCount = TempCount +
1
Next cl
Set cl = Nothing
CountByColor = TempCount
End Function


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
A UDF for Counting Coloured Cells that are conditionally formatted NeilG New Users to Excel 5 November 1st 09 12:45 AM
Conditionally Formatted Cells amy Excel Discussion (Misc queries) 1 February 23rd 08 07:28 AM
Can you add the number of conditionally formatted cells?? Lost Excel Worksheet Functions 1 January 23rd 07 06:31 AM
Counting conditionally formatted cells Kebbon Excel Worksheet Functions 2 October 12th 06 01:48 PM
Counting colour formatted cells Hood Excel Worksheet Functions 2 June 23rd 06 03:14 PM


All times are GMT +1. The time now is 01:33 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"