Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 4
Default Counting coloured cells

Hi

I've used the following code to count the number of cells in a range that are filled yellow, using the basic funtion '=CountYellow(A1:A99)'

Function CountYellow(MyRange As Range)
Dim iCount As Integer
Application.Volatile
iCount = 0
For Each cell In MyRange
If cell.Interior.ColorIndex = 6 Then
iCount = iCount + 1
End If
Next cell
CountYellow = iCount
End Function

However I now need to count the same range of cell that are coloured but contain only zeros, any ideas?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,533
Default Counting coloured cells

Hi

You can add some conditions to the if statement:

If cell.Interior.ColorIndex = 6 And cell.Value < "" And cell.Value = 0 Then

If you use the below it will count empty cells as 0:

If cell.Interior.ColorIndex = 6 And cell.Value = 0 Then

Regards,
Per

"SNC-DW" skrev i meddelelsen
...

Hi

I've used the following code to count the number of cells in a range
that are filled yellow, using the basic funtion '=CountYellow(A1:A99)'

Function CountYellow(MyRange As Range)
Dim iCount As Integer
Application.Volatile
iCount = 0
For Each cell In MyRange
If cell.Interior.ColorIndex = 6 Then
iCount = iCount + 1
End If
Next cell
CountYellow = iCount
End Function

However I now need to count the same range of cell that are coloured
but contain only zeros, any ideas?

Thanks




--
SNC-DW


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,722
Default Counting coloured cells

'Changed function name for clarity

Function CountYellowAndZero(MyRange As Range)
Dim iCount As Integer
Application.Volatile
iCount = 0
For Each cell In MyRange
'added criteria
If cell.Interior.ColorIndex = 6 And _
cell.Value = 0 And cell.Value < "" Then
iCount = iCount + 1
End If
Next cell
CountYellow = iCount
End Function

--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"SNC-DW" wrote:


Hi

I've used the following code to count the number of cells in a range
that are filled yellow, using the basic funtion '=CountYellow(A1:A99)'

Function CountYellow(MyRange As Range)
Dim iCount As Integer
Application.Volatile
iCount = 0
For Each cell In MyRange
If cell.Interior.ColorIndex = 6 Then
iCount = iCount + 1
End If
Next cell
CountYellow = iCount
End Function

However I now need to count the same range of cell that are coloured
but contain only zeros, any ideas?

Thanks




--
SNC-DW

  #4   Report Post  
Junior Member
 
Posts: 4
Smile

Thanks for your help guys, much appreciated!

Quote:
Originally Posted by Luke M View Post
'Changed function name for clarity

Function CountYellowAndZero(MyRange As Range)
Dim iCount As Integer
Application.Volatile
iCount = 0
For Each cell In MyRange
'added criteria
If cell.Interior.ColorIndex = 6 And _
cell.Value = 0 And cell.Value < "" Then
iCount = iCount + 1
End If
Next cell
CountYellow = iCount
End Function

--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"SNC-DW" wrote:


Hi

I've used the following code to count the number of cells in a range
that are filled yellow, using the basic funtion '=CountYellow(A1:A99)'

Function CountYellow(MyRange As Range)
Dim iCount As Integer
Application.Volatile
iCount = 0
For Each cell In MyRange
If cell.Interior.ColorIndex = 6 Then
iCount = iCount + 1
End If
Next cell
CountYellow = iCount
End Function

However I now need to count the same range of cell that are coloured
but contain only zeros, any ideas?

Thanks




--
SNC-DW
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
Counting coloured cells SNC-DW Excel Worksheet Functions 0 October 12th 09 12:35 PM
Counting coloured cells SNC-DW Excel Worksheet Functions 0 October 12th 09 12:35 PM
Counting Coloured Row Aslam Excel Worksheet Functions 1 September 9th 07 06:27 PM
Counting coloured cells amvena Excel Discussion (Misc queries) 2 August 19th 05 02:40 PM
counting coloured cells Tony Excel Worksheet Functions 3 April 7th 05 10:17 AM


All times are GMT +1. The time now is 06:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"