I need help trying to get a count of cells that have a specific fill color and certain value. It would be like how many pink cells contain the value 3.
The CountColorValue you posted is not a Function, it is a Sub Procedure.
You cannot call Sub Procedure like you do a function, you simply run it from the Macro Menu (or attach the code to a button or keyboard shortcut).
Dim numbers As Long, lastrow As Long
Dim rng As Range, c As Range
'Find the last row
lastrow = Range("B" & Rows.Count).End(xlUp).Row
'Set the range you want to search through
Set rng = Range("B1:B" & lastrow)
'Iterate through each cell in the range
For Each c In rng
'If the interior color is 2 (standard pink), not blank and not a number
If c.Interior.ColorIndex = "22" And c.Value = 3 Then '<> "" And Not IsNumeric(c.Value) Then
'Add 1 to numbers
numbers = numbers + 1
End If
Next c
'Message box with the value of numbers, change to display however you'd like
'MsgBox numbers
Let's take a step back here and make sure we define all the requirements.
What can you tell me about the range you want to run this on?
Will it be the same column every time, or does it need to be dynamic?
Where do you want the results returned to, a specific cell, a message box, a VBA variable?
The count would run for a single column and give the value underneath that column. It would also need to be dynamic, because it will look for a two different colors and at time multiple values (pink - female, cyan - male, shift - 12, 23, 1, 2, 3).
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.