Forum Discussion
Percentage of 2 colors from a column to a cell
help_please360 You'll need some VBA code for this. Not my favorite subject but something I did a long time ago. This peace of code creates a user defined function that let's you count the number of cells with the same color as the cell where the formula is entered. From there you can divide the outcome by the total number of cells and format as a percentage.
Function CountColor(rngCol As Range)
Application.Volatile
Dim C As Long
Dim Total As Variant
C = Application.ThisCell.Interior.Color
Total = 0
For Each Cell In rngCol
If Cell.Interior.Color = C Then
Total = Total + 1
End If
Next
CountColor = Total
End FunctionI've attached a file with a working example of what you described.
- help_please360May 29, 2022Copper Contributor
Riny_van_Eekelen thanks for the reply my friend. It would be almost that! I need cell D57 to show me only the % of the most repeated color in column D2:D46. I will send you a picture for you to see! Hope you can help me, thanks!
- Riny_van_EekelenMay 29, 2022Platinum Contributor
help_please360 You'll need the two cells that calculate the % for each color, but you can hide them somewhere. D57 will then contain a formula that takes the maximum of the two. Use conditional formatting to color D57 reg or green. See attached.
- help_please360May 30, 2022Copper Contributor
Riny_van_Eekelen thank you my friend, it worked! I just need now that this result has a color scale for the percentage of red and green. I tried to make this color scale in a few ways but ended up replacing the main rule that takes the cell with the highest %.. could you tell me how I can put this coloring rule in the same image below ? Thank you for your help