Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default "COUNTIF" using ".ColorIndex" and "AND"

I am trying to count the number of cells in a range that have
..Font.ColorIndex=6
AND
..Interior.ColorIndex=[1, 2, 3 or 4]

I've tried using the UDFs from http://www.cpearson.com/excel/colors.htm but
I'm having no luck in combining these with a formula.

Does anyone know how to do this?

Kind regards,
Samuel Harmer
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default "COUNTIF" using ".ColorIndex" and "AND"

Function CountByColor(InRange As Range, _
FontColorIndex As Integer, _
InteriorColorIndexMin As Integer, _
InteriorColorIndexMax As Integer) As Long

Dim Rng As Range
Application.Volatile True

For Each Rng In InRange.Cells
If Rng.Font.ColorIndex = FontColorIndex And _
Rng.Interior.ColorIndex = InteriorColorIndexMin And _
Rng.Interior.ColorIndex <= InteriorColorIndexMax _
Then CountByColor = CountByColor + 1
Next Rng

End Function

Hth,
Merjet


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default "COUNTIF" using ".ColorIndex" and "AND"

How about:

Sub styne()
IAmTheCount = 0
Set r = Selection
For Each rr In r
i = rr.Font.ColorIndex
j = rr.Interior.ColorIndex
If i = 6 And j < 5 Then
IAmTheCount = IAmTheCount + 1
End If
Next
MsgBox (IAmTheCount)
End Sub
--
Gary's Student
gsnu200704


"styne666" wrote:

I am trying to count the number of cells in a range that have
.Font.ColorIndex=6
AND
.Interior.ColorIndex=[1, 2, 3 or 4]

I've tried using the UDFs from http://www.cpearson.com/excel/colors.htm but
I'm having no luck in combining these with a formula.

Does anyone know how to do this?

Kind regards,
Samuel Harmer

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
Difficulty "countif"-ing number of "L1" or "L2" on an autofiltered pmdoherty Excel Worksheet Functions 4 February 6th 09 11:23 AM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM


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