Reputation: 1
I have two columns in an excel sheet,
I want to check whether both columns are exactly same or not. Same I mean to say the sequence itself (Ax should be same as Bx).
For example,
A B
x1 x1
x2 x2
x3 x3
x4 y4
Here 4th column should be highlighted as x4 and y4 are not same.
Thanks
Upvotes: 0
Views: 122
Reputation: 34230
You could also use an array formula to find the first row (if any) where the two cells don't match:-
=IFERROR("Difference in row "&MATCH(TRUE,A:A<>B:B,0),"No Difference")
(must be entered with Ctrl Shift Enter )
Upvotes: 0
Reputation: 2502
Three options:
Conditional Format
If you just want to highlight differences, add a conditional format.
Formula
If you want to know whether or not ANY cell in column A or B is different, you
MACRO
Add a macro and do something with it. This macro will just paste result into cell E1 and display a message box when you run it.
Sub ColumnCheck()
Dim i, LastRow, LastRowA, LastRowB, response
'get last row in column A and B, rather than
'iterating through all possible rows
LastRowA = Range("A" & Rows.Count).End(xlUp).Row
LastRowB = Range("A" & Rows.Count).End(xlUp).Row
'get the greatest row between A and B
If LastRowA >= LastRowB Then
LastRow = LastRowA
Else
LastRow = LastRowB
End If
'iterate through all rows comparing them.
For i = 1 To LastRow
If Cells(i, "A").Value <> Cells(i, "B").Value Then
response = "The columns are not equal!"
Range("E1") = response
MsgBox (response)
Exit Sub
End If
Next
response = "The columns are equal!"
Range("E1") = response
MsgBox (response)
End Sub
Upvotes: 1