I created the following user defined function:
Function FontColor(r As Range) As Integer
FontColor = r.Font.ColorIndex
End Function
Now I need to count only the rows that have "cat" in column A as well as red font in column B:
[TABLE="width: 128"]
<tbody>[TR]
[TD="class: xl65"]A[/TD]
[TD="class: xl65, width: 64"]B[/TD]
[/TR]
[TR]
[TD="class: xl63"]dog[/TD]
[TD="class: xl63"]8[/TD]
[/TR]
[TR]
[TD="class: xl63"]cat[/TD]
[TD="class: xl64"]9[/TD]
[/TR]
[TR]
[TD="class: xl63"]shoe[/TD]
[TD="class: xl63"]6[/TD]
[/TR]
[TR]
[TD="class: xl63"]cat[/TD]
[TD="class: xl64"]9[/TD]
[/TR]
[TR]
[TD="class: xl63"]shoe[/TD]
[TD="class: xl63"]42[/TD]
[/TR]
[TR]
[TD="class: xl63"]dog[/TD]
[TD="class: xl63"]8[/TD]
[/TR]
[TR]
[TD="class: xl63"]cat[/TD]
[TD="class: xl63"]7[/TD]
[/TR]
</tbody>[/TABLE]
The formula I'm using is this:
{=COUNT(IF(A:A="cat",IF(fontcolor(B:B)=3,B:B)))}
This tells excel to count the rows in column B, only when the left column is "cat" and the right column has a red font. But it's not working. I get the answer "0". However if I replace the user defined formula with a "built-in" one like this:
{=COUNT(IF(A:A="cat",IF(SQRT(B:B)=3,B:B)))}
The formula works well, I get the answer "2". This tells me that somehow user-defined functions don't work within array formulas, OR they need to be modified to work within array formulas.
Any suggestions, or comments?
Function FontColor(r As Range) As Integer
FontColor = r.Font.ColorIndex
End Function
Now I need to count only the rows that have "cat" in column A as well as red font in column B:
[TABLE="width: 128"]
<tbody>[TR]
[TD="class: xl65"]A[/TD]
[TD="class: xl65, width: 64"]B[/TD]
[/TR]
[TR]
[TD="class: xl63"]dog[/TD]
[TD="class: xl63"]8[/TD]
[/TR]
[TR]
[TD="class: xl63"]cat[/TD]
[TD="class: xl64"]9[/TD]
[/TR]
[TR]
[TD="class: xl63"]shoe[/TD]
[TD="class: xl63"]6[/TD]
[/TR]
[TR]
[TD="class: xl63"]cat[/TD]
[TD="class: xl64"]9[/TD]
[/TR]
[TR]
[TD="class: xl63"]shoe[/TD]
[TD="class: xl63"]42[/TD]
[/TR]
[TR]
[TD="class: xl63"]dog[/TD]
[TD="class: xl63"]8[/TD]
[/TR]
[TR]
[TD="class: xl63"]cat[/TD]
[TD="class: xl63"]7[/TD]
[/TR]
</tbody>[/TABLE]
The formula I'm using is this:
{=COUNT(IF(A:A="cat",IF(fontcolor(B:B)=3,B:B)))}
This tells excel to count the rows in column B, only when the left column is "cat" and the right column has a red font. But it's not working. I get the answer "0". However if I replace the user defined formula with a "built-in" one like this:
{=COUNT(IF(A:A="cat",IF(SQRT(B:B)=3,B:B)))}
The formula works well, I get the answer "2". This tells me that somehow user-defined functions don't work within array formulas, OR they need to be modified to work within array formulas.
Any suggestions, or comments?