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

#### Denny57

##### New Member
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

### 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
Excel Formula:
``=IF(COUNTIFS(A1:E1,"B"),0,COUNTIFS(A1:E1,"A"))``

#### jasonb75

##### Well-known Member
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
Or this /
Excel Formula:
``=IF(ISERROR(MATCH("B",A1:E1,0)),COUNTIFS(A1:E1,"A"),"")``

##### Well-known Member

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
Thank you all.. Fluff. it works perfectly as I need

#### Fluff

##### MrExcel MVP, Moderator
Glad we could help & thanks for the feedback.

Replies
3
Views
53
Replies
6
Views
107
Replies
9
Views
172
Replies
5
Views
251
Replies
6
Views
166

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.

### Which adblocker are you using?

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

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