COUNTIF a cell in a row does not equal the cell to right of it.

tamdunk

New Member
Joined
Feb 9, 2018
Messages
8
Hi, I'm trying to make a function to count the instances where one cell has a different value to the cell beside it. the columns are effectively pairs so I'm only looking to where count every pair of cells do not match. I tried the following formula, but cant get the syntax right, am not sure if it would even work.

=COUNTIF(MOD(G2:R2,2)=0, (MOD(G2:R2,2)=0) <> (MOD(G2:R2, 2) =1))

I managed to get the required outcome by making a macro,

Code:
For I = Range("G2").Column To Range("R2").Column Step 2
         If Cells(2, I).Value <> Cells(2, (I + 1)).Value Then
         difTot = difTot + 1
         End If
Next I

but I'd rather have it as a formula if at all possible. Any help would be appreciated.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Are you counting every other row?
How far down do you need to go?
 
Upvote 0
Are we talking about comparing columns or rows? Columns this will work but change the range to suit:

=SUMPRODUCT(--(A:A<>B:B)
 
Upvote 0
Code:
G        H        I        J        L     K       DIFFERENCE
GOOD     GOOD     GOOD    BAD    GOOD     BAD          2


This is what I'm getting at, so because I & J and L & K dont match, the total in difference would be 2
 
Upvote 0
Hi we're comparing every 2nd column with the one beside it so is column G different to H, is I different to J, is K different L etc. And counting each occurance where they don't match. It'll be for a couple of hundred rows in the end.
 
Upvote 0
You could get your example like this:

=SUMPRODUCT(--(G1:K1<>H1:L1),MOD(COLUMN(G1:K1),2))
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,206
Members
453,022
Latest member
RobertV1609

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