udf to count colour in a matrix

uk747

Well-known Member
Joined
Jul 20, 2011
Messages
744
Office Version
  1. 365
Platform
  1. Windows
have a udf to count a colour
=Countcolour($A$1:$M$13,U$1)

what if i want to add a wider range , i.e.
B1:M1,C2:M2,D3:M3,E4:M4,F5:M5,G6:M6,H7:M7,I8:M8,J9:M9,K10:M10,L11:M11,M12
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,887
Hi

It would help if you post the udf. I'm sure there are several udf's with that name available on the web.
 
Last edited:

uk747

Well-known Member
Joined
Jul 20, 2011
Messages
744
Office Version
  1. 365
Platform
  1. Windows
Hi

It would help if you post the udf. I'm sure there are several udf's with that name available on the web.

was copied from elsewhere

Code:
Function Countcolour(rng As Range, colour As Range) As Long
Dim c As Range
Application.Volatile
For Each c In rng
    If c.Interior.ColorIndex = colour.Interior.ColorIndex Then
        Countcolour = Countcolour + 1
    End If
Next
End Function
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
37,883
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Just pass the range you indicated encased in a set of parentheses...

=Countcolour((B1:M1,C2:M2,D3:M3,E4:M4,F5:M5,G6:M6,H7:M7,I8:M8,J9:M9,K10:M10,L11:M11,M12),A2)
 

uk747

Well-known Member
Joined
Jul 20, 2011
Messages
744
Office Version
  1. 365
Platform
  1. Windows
Just pass the range you indicated encased in a set of parentheses...

=Countcolour((B1:M1,C2:M2,D3:M3,E4:M4,F5:M5,G6:M6,H7:M7,I8:M8,J9:M9,K10:M10,L11:M11,M12),A2)

thanks Rick, i did manage to do it with formula below but yours is alot better :)

=Countcolour(B$1:M$1,Y$1) + Countcolour(C$2:M$2,Y$1) + Countcolour(D$3:M$3,Y$1) + Countcolour(E$4:M$4,Y$1) + Countcolour(F$5:M$5,Y$1) + Countcolour(G$6:M$6,Y$1) + Countcolour(H$7:M$7,Y$1) + Countcolour(I$8:M$8,Y$1) + Countcolour(J$9:M$9,Y$1) + Countcolour(K$10:M$10,Y$1) + Countcolour(L$11:M$11,Y$1) + Countcolour(M$12,Y$1)
 

uk747

Well-known Member
Joined
Jul 20, 2011
Messages
744
Office Version
  1. 365
Platform
  1. Windows
just noticed one sligt problem when i run a macro to clear the cells colours the formula doesnt update until i click on F9

i did add Application.Calculation = xlAutomatic but itt didnt need it before
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,147
Messages
5,835,673
Members
430,374
Latest member
PeteBrown

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top