Comparing to tables of data to confirm they are the same or not

R

Roger on Excel

I have a table with 5 columns and 60 rows which contains text and numerical
data.

The table is in columns B,C,D,E,F.

I would like to utilize a macro to compare this table with another table (in
columns G,H,I,J,K) for differences and to return a True or False value (in
cell A65) if they are the same or different.

can anyone help?

ThankYou,

Roger
 
O

Otto Moehrbach

Roger
This little macro will compare B1:F60 with G1:K60 and will place False
or True in A65 if a difference is found or not. Note that if there is a
difference, the code will not check beyond the first difference found. HTH
Otto
Sub TestCompare()
Dim i As Range
Dim Good As Boolean
Good = True
For Each i In Range("B1:F60")
If i <> i.Offset(, 5) Then
Good = False
Exit For
End If
Next i
Range("A65") = Good
End Sub
 
L

Lionel H

Roger,
Not sure why you just want a flag if the tables contains differences -
you've then got to go find them!
The following highlights the differing cells. (but puts you flag in as well
in case you use it for some other purpose)

Sub compare()
Range("A65") = "True" 'Assume the answer true
For i = 2 To 6
For j = 1 To 60
If Cells(j, i) = Cells(j, i + 5) Then
Cells(j, i).Interior.ColorIndex = 4 'green
Cells(j, i + 5).Interior.ColorIndex = 4 'green
Else
Cells(j, i).Interior.ColorIndex = 3 'red
Cells(j, i + 5).Interior.ColorIndex = 3 'red
Range("A65") = "False" 'go false if you ever come through here
End If
Next j
Next i
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top