Count conditional cells with CountIf

ace3g

New Member
Joined
Feb 26, 2020
Messages
5
Office Version
  1. 365
If I have a condition =COUNTIF($M$2:$R$27,B2)>=1 that turns certain cells green, how can I count those cells in row that are green? Range that turns green is: =B2:G39 (based on number inputted in M2:R27)-- First row I want to count is B2:G2.

I think I almost figured it out: =SUM(COUNTIF(B2:G2,$M$2:$R$27)) but I only want it to count the first time a number in B2:G2 matches numbers from M2:R27, no duplicates.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Welcome to the forum. :)

Please just take a minute to read the forum rules on cross-posting and make sure to follow them in future. Thanks.

Cross-posted here.
 
Upvote 0
You can't upload the actual file to this site (though you can put it elsewhere and link to it here) but see the links in my signature for details of the forum add-in for posting tables of your sheet here.
 
Upvote 0
Below is a screen cap of my sheet if that helps. The total for B2:G2 should be 6 not 18 and B3:G3 should be 4. Currently looking at numbers entered in M2:R4. Since there are multiple 1s and 3s it keeps counting those.

1582813567824.png
 
Upvote 0
Try this:

=SUM(--(COUNTIF($M$2:$R$27,$B2:$G2)>0))

which needs to be array-entered with Ctrl+Shift+Enter, or:

=SUMPODUCT(--(COUNTIF($M$2:$R$27,$B2:$G2)>0))

which can be normally entered.
 
Upvote 0
Wow thank you very much, this worked!!!

You can mark this as being solved and I'll forward over to the cross post.
 
Upvote 0
We don't actually mark threads as solved here, but I'm glad to help.
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,721
Members
449,093
Latest member
Mnur

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