# Countif using a range comparison

#### smurphy1977

##### New Member
I am trying to come up with a Countif formual using a range comparison but I don't know if it is possible.

What I a trying to do is to count how many cells differences there are . For example if A1 does not equal B1 then count, if A2 does not equal B2 then count.

A B
1 1
1 2
2 1
2 2

If I had the correct formula in this example I should generate a count of 2.

I just can't get it to work. Can anyone help? Is it even possible?

I was thinking =COUNTIF(A1:A4, "<>B1:B4") but that doesn't work. Doing it that way it counts everthing and gives me a 4

-Sage

### Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

#### MrKowz

##### Well-known Member
Try the following:
Excel Workbook
ABCD
1112
212
321
422
Sheet1
Excel 2003
#VALUE!
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.

##### MrExcel MVP
I am trying to come up with a Countif formual using a range comparison but I don't know if it is possible.

What I a trying to do is to count how many cells differences there are . For example if A1 does not equal B1 then count, if A2 does not equal B2 then count.

A B
1 1
1 2
2 1
2 2

If I had the correct formula in this example I should generate a count of 2.

I just can't get it to work. Can anyone help? Is it even possible?

I was thinking =COUNTIF(A1:A4, "<>B1:B4") but that doesn't work. Doing it that way it counts everthing and gives me a 4

-Sage

Try...

=SUMPRODUCT((A1:A4<>B1:B4)+0)

#### smurphy1977

##### New Member
Awesome! Would you be able to talk me through the logic because I am trying to wrap my head around it.

I've got = Count (if range 1 does not equal range 2, then ......)

and then I get lost.

And say I wanted to excude any 3's that were in column b in the count what would I add then.
Would it be:

=COUNT(IF(A1:A4<>B1:B4,A1:A4,""))-Count(if(B1:B4=3,1,0) ????

Try the following:

Excel Workbook
ABCD
1112
212
321
422
Sheet1
Excel 2003
#VALUE!
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}. Note: Do not try and enter these manually yourself

#### delaneyjm

##### Well-known Member

Bit late as usual...

=SUMPRODUCT(--(A2:A6<>B2:B6))

#### smurphy1977

##### New Member
I like this one too! Forgive me if this is a dumb question but what does the "--" mean in the formula?

Bit late as usual...

=SUMPRODUCT(--(A2:A6<>B2:B6))

#### delaneyjm

##### Well-known Member
it converts the true's and false's returned by the A2:A6<>B2:B6 into 1's and 0's. 1 being true and 0 being false.

Replies
5
Views
251
Replies
4
Views
136
Replies
4
Views
634
Replies
6
Views
131
Replies
5
Views
286

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,152,041
Messages
5,767,789
Members
425,435
Latest member
cmardaz

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