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

Denny57

New Member
Joined
Nov 23, 2015
Messages
49
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
 

Some videos you may like

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,412
Office Version
  1. 365
Platform
  1. Windows
How about
Excel Formula:
=IF(COUNTIFS(A1:E1,"B"),0,COUNTIFS(A1:E1,"A"))
 
Solution

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
12,432
Office Version
  1. 365
Platform
  1. Windows
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.
 

alz

Board Regular
Joined
Jul 17, 2020
Messages
130
Office Version
  1. 2019
Platform
  1. Windows
Or this /
Excel Formula:
=IF(ISERROR(MATCH("B",A1:E1,0)),COUNTIFS(A1:E1,"A"),"")
 

Toadstool

Well-known Member
Joined
Mar 5, 2018
Messages
1,384
Office Version
  1. 2016
Platform
  1. Windows

ADVERTISEMENT

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)))
 

Denny57

New Member
Joined
Nov 23, 2015
Messages
49
Office Version
  1. 365
Platform
  1. Windows
Thank you all.. Fluff. it works perfectly as I need
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,412
Office Version
  1. 365
Platform
  1. Windows
Glad we could help & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,318
Messages
5,623,974
Members
416,002
Latest member
Neshx

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
Top