Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare Two Ranges Objects

Status
Not open for further replies.

cameronfraser

Programmer
May 18, 2001
13
US
How do I compare two headers on two separate Excel spreadsheets using VBA using range objects?

The headers are made up of a range of cells A1:Q3. On Sheet1 I set the header range as the object Range1. On Sheet2 I set the header range as Range2.

Worksheets("Sheet1").Range("A1","Q3").Select
Set Range1 = Selection
Worksheets("Sheet2").Range("A1","Q3").Select
Set Range2 = Selection


Now, How do I compare Range1 to Range2 to see if they each contain the same data.



 
Sub findDiff()

For Row = 1 To 3
For Column = 1 To 17 'A to Q

If Worksheets(1).Cells(Row, Column).Value <> _
Worksheets(2).Cells(Row, Column).Value Then
Rsp = MsgBox(&quot;Heading different in cell: &quot; & _
Chr(64 + Column) & LTrim(Str(Row)), vbCritical)
anyErrors = True
End If

Next Column
Next Row

If Not anyErrors Then
Rsp = MsgBox(&quot;Headings are identical.&quot;, vbExclamation)
End If

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top