Count green cells in a row?

samilynn

Board Regular
Joined
Jun 24, 2003
Messages
185
Office Version
  1. 2016
Platform
  1. Windows
is there a formula or VBA code that can count the green colored cells in a single Row? I'm also going to use it for Red cells btw...if any of this is possible.

Thank you!

Samantha
 
Check:


 
Upvote 0
It depends on how the cells were colored red/green. If they were colored manually, you will need to use VBA code, like in the links Dante provided.
If they are being colored by Conditional Formatting, you may be able to use the same criteria in a COUNTIFS formula to get your counts.
 
Upvote 0
You can use the following CountColor() function, it works for both cells with conditional formatting and cells with manual color.

Dante Amor
ABCDEF
1
243
3
4CF1Manually
5Manually2Manually
6CF1Manually
7ManuallyManually
8ManuallyManually
9ManuallyManually
10ManuallyManually
Hoja2
Cell Formulas
RangeFormula
C2,F2C2=CountColor(B4:B10,B2)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B4:B6Cell Value=1textNO


Put the following in a module. In the cell use CountColor function, like in the example above.
VBA Code:
Function CountColor(cRange As Range, cColor As Range) As Long
  Dim c As Range
  Application.Volatile
  For Each c In cRange
    If Evaluate("nIntColor(" & c.Address() & ")") = cColor.Interior.Color Then
      CountColor = CountColor + 1
    End If
  Next
End Function

Private Function nIntColor(ByVal miRango As Range) As Double
  nIntColor = miRango.DisplayFormat.Interior.Color
End Function

🤗
 
Upvote 0
Solution
You can use the following CountColor() function, it works for both cells with conditional formatting and cells with manual color.

Dante Amor
ABCDEF
1
243
3
4CF1Manually
5Manually2Manually
6CF1Manually
7ManuallyManually
8ManuallyManually
9ManuallyManually
10ManuallyManually
Hoja2
Cell Formulas
RangeFormula
C2,F2C2=CountColor(B4:B10,B2)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B4:B6Cell Value=1textNO


Put the following in a module. In the cell use CountColor function, like in the example above.
VBA Code:
Function CountColor(cRange As Range, cColor As Range) As Long
  Dim c As Range
  Application.Volatile
  For Each c In cRange
    If Evaluate("nIntColor(" & c.Address() & ")") = cColor.Interior.Color Then
      CountColor = CountColor + 1
    End If
  Next
End Function

Private Function nIntColor(ByVal miRango As Range) As Double
  nIntColor = miRango.DisplayFormat.Interior.Color
End Function

🤗
Thank you Dante, this is PERFECT!!!
 
Upvote 0

Forum statistics

Threads
1,226,798
Messages
6,193,063
Members
453,773
Latest member
bclever07

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
Back
Top