tyija1995
Well-known Member
- Joined
- Feb 26, 2019
- Messages
- 781
- Office Version
- 365
- Platform
- Windows
Hi all,
I have a range of values (B2:B11) that have multiple Conditional Formatting (CF) rules, I am now trying to make a UDF that will count how many cells are orange for example.
I have used the following procedure to decipher what the colour index is of the orange cell:
Which returns 44 when I test, this is fine, so I have then made the following but it doesn't quite work:
This returns 0 even though all of the cells are orange for testing purposes.
If I change
to:
I get #VALUE ! when I use the function.
With B2:B11 CF'd to orange, I am expecting to see =COUNTORANGE(B2:B11) return 10. Any ideas?
Thanks!
I have a range of values (B2:B11) that have multiple Conditional Formatting (CF) rules, I am now trying to make a UDF that will count how many cells are orange for example.
I have used the following procedure to decipher what the colour index is of the orange cell:
Code:
Sub ColourMessage()
MsgBox ActiveCell.DisplayFormat.Interior.ColorIndex
End Sub
Which returns 44 when I test, this is fine, so I have then made the following but it doesn't quite work:
Code:
Function COUNTORANGE(rng As Range)
Dim cell As Range
COUNTORANGE = 0
For Each cell In rng
If cell.Interior.ColorIndex = 44 Then
COUNTORANGE = COUNTORANGE + 1
End If
Next cell
End Function
This returns 0 even though all of the cells are orange for testing purposes.
If I change
Code:
If cell.Interior.ColorIndex = 44 Then
Code:
If cell.DisplayFormat.Interior.ColorIndex = 44 Then
I get #VALUE ! when I use the function.
With B2:B11 CF'd to orange, I am expecting to see =COUNTORANGE(B2:B11) return 10. Any ideas?
Thanks!