Only count items in a range when a defined value is not in that range

Denny57

Board Regular
Joined
Nov 23, 2015
Messages
183
Office Version
  1. 365
Platform
  1. Windows
I am looking to count the number of cells in a range which contain a specifc value but only if that range does not contain another specific value

EXAMPLE = Only count cells that contain the value "A" when the value "B" is not in the range.
Range A1:E1
Cell Values: A1 = A, B1 = A, C1 = A, D1 = B, E1 = D
As cell D1 contains the value "B" then the expected returned count value would be 0.

However if cell D1 contains a different value (e.g. C), then the returned count value would be 3
Range A1:E1
Cell Values: A1 = A, B1 = A, C1 = A, D1 = C, E1 = D

These are only example variables

Thanks in advance
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
How about
Excel Formula:
=IF(COUNTIFS(A1:E1,"B"),0,COUNTIFS(A1:E1,"A"))
 
Upvote 0
Solution
Assuming that you meant A for the second example and not C, try something on the lines of
Excel Formula:
=COUNTIF(A1:E1,D1)*(D1<>"B")
edit:- ignore this, after seeing Fluff's reply above I realised that I misread part of the question.
 
Upvote 0
Or this /
Excel Formula:
=IF(ISERROR(MATCH("B",A1:E1,0)),COUNTIFS(A1:E1,"A"),"")
 
Upvote 0
Hi Denny57,

Does this work for you?

Denny.xlsx
ABCDEFG
1AAABD0
2AAACD3
3BAACD0
4AAAAA5
5BBBBB0
6AACDD2
Sheet0
Cell Formulas
RangeFormula
G1:G6G1=COUNTIF(A1:E1,"A")*(ISNA(MATCH("B",A1:E1,0)))
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,981
Members
448,538
Latest member
alex78

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