Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,560
Default Is there a way to count cells in a range with a given backcolor?

Is there a function to count the cells in a range, which have a given
interior color?
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,942
Default Is there a way to count cells in a range with a given backcolor?

hi
Sub countcolor()
Dim rng As Range
Dim cnt As Long

Set rng = Range("A2:I30")
cnt = 0

For Each cell In rng
If cell.Interior.ColorIndex = 40 Then
cnt = cnt + 1
End If
Next
MsgBox cnt
'or Range("K2").Value = cnt

End Sub

see this site for color indexes...
http://www.mvps.org/dmcritchie/excel/colors.htm

regards
FSt1

"David" wrote:

Is there a function to count the cells in a range, which have a given
interior color?

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,856
Default Is there a way to count cells in a range with a given backcolor?

Have a look at this link:

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

Although this is about sorting by colour, it gives you some UDFs which
will return the colour information to another column - you can then do
a COUNTIF on that column, something like:

=COUNTIF(B1:B100,4)

assuming the colour information is in column B and you are interested
in colour number 4.

Hope this helps.

Pete


On Oct 17, 11:12 am, David wrote:
Is there a function to count the cells in a range, which have a given
interior color?



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default Is there a way to count cells in a range with a given backcolor?

Checks a range for the same colour as in A1

Sub countcolours()
Clr = Range("A1").Interior.Color
Set Myrange = Range("B1:B100")
For Each c In Myrange
If c.Interior.Color = Clr Then
CountColour = CountColour + 1
End If
Next
MsgBox "There are " & CountColour & " cells the same colour as A1"
End Sub

Mike

"David" wrote:

Is there a function to count the cells in a range, which have a given
interior color?

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,560
Default Is there a way to count cells in a range with a given backcolo

Thanks, Mike. I knew how to do this by macro. I need a function, like
(pseudo code) "=if(interiorcolor=green, "Yes", "No").

I do recall reading an article some time ago about how this can be done.


"Mike H" wrote:

Checks a range for the same colour as in A1

Sub countcolours()
Clr = Range("A1").Interior.Color
Set Myrange = Range("B1:B100")
For Each c In Myrange
If c.Interior.Color = Clr Then
CountColour = CountColour + 1
End If
Next
MsgBox "There are " & CountColour & " cells the same colour as A1"
End Sub

Mike

"David" wrote:

Is there a function to count the cells in a range, which have a given
interior color?



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,593
Default Is there a way to count cells in a range with a given backcolor?

See http://www.xldynamic.com/source/xld.ColourCounter.html for a working
solution

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"David" wrote in message
...
Is there a function to count the cells in a range, which have a given
interior color?



  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,560
Default Is there a way to count cells in a range with a given backcolo

Thanks, FSt1. Good name!

I knew how to do this by macro. There is a way (I read an article some time
ago) of using a function, like "=if(interiorcolor=green, "Yes", "No"). It
can be done, I just can't remember how.




"FSt1" wrote:

hi
Sub countcolor()
Dim rng As Range
Dim cnt As Long

Set rng = Range("A2:I30")
cnt = 0

For Each cell In rng
If cell.Interior.ColorIndex = 40 Then
cnt = cnt + 1
End If
Next
MsgBox cnt
'or Range("K2").Value = cnt

End Sub

see this site for color indexes...
http://www.mvps.org/dmcritchie/excel/colors.htm

regards
FSt1

"David" wrote:

Is there a function to count the cells in a range, which have a given
interior color?

  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,560
Default Is there a way to count cells in a range with a given backcolo

Thanks, Pete.

I read an article some time ago function to return interior colour of a
cell. It's not necessary to use a user-defined function. But I can't
remember how. I'm sure there are functions to return all kinds of info about
a cell's formatting.



"Pete_UK" wrote:

Have a look at this link:

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

Although this is about sorting by colour, it gives you some UDFs which
will return the colour information to another column - you can then do
a COUNTIF on that column, something like:

=COUNTIF(B1:B100,4)

assuming the colour information is in column B and you are interested
in colour number 4.

Hope this helps.

Pete


On Oct 17, 11:12 am, David wrote:
Is there a function to count the cells in a range, which have a given
interior color?




  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,560
Default Is there a way to count cells in a range with a given backcolo

Thanks, Bob.

I read an article some time ago function to return interior colour of a
cell. It's not necessary to use a user-defined function. But I can't
remember how. I'm sure there are built-in functions to return all kinds of
info about a cell's formatting.



"Bob Phillips" wrote:

See http://www.xldynamic.com/source/xld.ColourCounter.html for a working
solution

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"David" wrote in message
...
Is there a function to count the cells in a range, which have a given
interior color?




  #10   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default Is there a way to count cells in a range with a given backcolo

I do not believe Excel has any inbuilt functions for working with cell
colours outside of conditional formatting so I suggest it's either a Sub or a
function.

"David" wrote:

Thanks, Mike. I knew how to do this by macro. I need a function, like
(pseudo code) "=if(interiorcolor=green, "Yes", "No").

I do recall reading an article some time ago about how this can be done.


"Mike H" wrote:

Checks a range for the same colour as in A1

Sub countcolours()
Clr = Range("A1").Interior.Color
Set Myrange = Range("B1:B100")
For Each c In Myrange
If c.Interior.Color = Clr Then
CountColour = CountColour + 1
End If
Next
MsgBox "There are " & CountColour & " cells the same colour as A1"
End Sub

Mike

"David" wrote:

Is there a function to count the cells in a range, which have a given
interior color?



  #11   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,651
Default Is there a way to count cells in a range with a given backcolo

The CELL function returns information about formatting in terms of number
format and whether it is coloured for negative numbers, but doesn't include
picking up basic colour formatting of cells. If you think it's not
necessary to use a user-defined function, I'm sure the readers of the group
will be interested to hear you tell them how you'll do it without.
--
David Biddulph

"David" wrote in message
...
Thanks, Pete.

I read an article some time ago function to return interior colour of
a
cell. It's not necessary to use a user-defined function. But I can't
remember how. I'm sure there are functions to return all kinds of info
about
a cell's formatting.


"Pete_UK" wrote:

Have a look at this link:

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

Although this is about sorting by colour, it gives you some UDFs which
will return the colour information to another column - you can then do
a COUNTIF on that column, something like:

=COUNTIF(B1:B100,4)

assuming the colour information is in column B and you are interested
in colour number 4.

Hope this helps.

Pete


On Oct 17, 11:12 am, David wrote:
Is there a function to count the cells in a range, which have a given
interior color?



  #12   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default Is there a way to count cells in a range with a given backcolor?

You could try this alternate method which doesn't use VBA.

In 2003 you can specify the Format color to look for under
EditFindOptionsFormatFormat.

Select the color from the Patterns dialog and Find All.

In the found dialog box the first cell will be highlighted. Hold SHIFT key and
scroll down to bottom of dialog box and select last cell.

The selected cells can then be counted by right-click on Status Bar and "Count".

Do for each color.


Gord Dibben MS Excel MVP

On Wed, 17 Oct 2007 03:12:01 -0700, David
wrote:

Is there a function to count the cells in a range, which have a given
interior color?


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
Count Certain Cells in Specified Range Xavier Excel Worksheet Functions 3 July 25th 06 10:25 PM
Count coloured cells in a range [email protected] Excel Worksheet Functions 3 July 20th 06 01:48 PM
Worksheet backcolor within range Stanley Excel Discussion (Misc queries) 2 January 25th 06 09:33 PM
count cells in a range fullers Excel Worksheet Functions 2 November 30th 05 01:36 PM
Count cells in one range based on parameters in another range dave roth Excel Worksheet Functions 2 March 29th 05 05:33 PM


All times are GMT +1. The time now is 12:45 PM.

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"