PDA

View Full Version : VBA - Count # of cells in Column B that are greater in value than in Column A



Goureyham
06-20-2020, 08:13 AM
Hi everyone,

I am trying to figure out some solution to comparing cells in a column to another and counting the number of cells that have a greater value than in one column.
For example, in the table below, I am trying to see if there is a code in counting the number of cells in Column B that have a greater value than in column A.


3

20



7

2



10

11



9

100



2

1











Thus far, I have done conditional formatting where I put in a New Rule, highlighting the cells in Column B that have a greater value than the cells Column A. It looks to see if B1>A1 then the cell color is blue
From there I count the number of cells by sorting by color and then manually counting (because I find it hard to code to count colored cells with conditional formatting). I have been trying hard to figure out a solution, but I am really stuck.
Would someone have be able to help?

mana
06-20-2020, 07:26 PM
msgbox evaluate("sumproduct(n(b1:b5>a1:a5))")

Goureyham
06-21-2020, 04:26 PM
Thank you Mana!
This worked!!