comparing two worksheets

umerhayyat

New Member
Joined
Mar 13, 2023
Messages
7
Office Version
  1. 2019
Platform
  1. Windows
Hi.

I'm wondering if anybody could help me with this or if it is possible.

I have two worksheets of data, each row is the same case on both sheets and the columns all contain the same variables I just need to know the differences between each row.

I'm looking for a VBA that could compare the two sheets row by row and output a list row by row of which cells differ?

I have tried to hunt something down but all I can find is VBA that would highlight the different cells which wont do for this task.

Any help would be greatly appreciated.

Many thanks,

Sheet1
1197326901000207002610175
700000​

Sheet
1197326901000205002610175
700000​
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
if you wanted VBA , cant help - but can be done with a formula and some helper columns
IFERROR(INDEX(Sheet1!A:A,AGGREGATE(15,6,ROW(Sheet1!$B$2:$B$11)/(Sheet1!$B$2:$B$11=0),ROWS(A$2:A2))),"")

or using filter - with NO helper columns - But i dont think 2019 version has the FILTER() function
=FILTER(A2:C6&" <- sheet1 sheet2->"&Sheet2!A2:C6,A2:A6&B2:B6&C2:C6<>Sheet2!A2:A6&Sheet2!B2:B6&Sheet2!C2:C6)

Book4
ABCDEFGHIJKLMN
1Data1Data2Data3Helpersheet 1 extractsheet 2 extract
21aa13cv3ac3 <- sheet1 sheet2->3
32bb15ed5ee5 <- sheet1 sheet2->5
43cv0000000
54dc1000000
65ed0000000
7000000
8000000
Sheet1
Cell Formulas
RangeFormula
F2:H8F2=IFERROR(INDEX(Sheet1!A:A,AGGREGATE(15,6,ROW(Sheet1!$D$2:$D$11)/(Sheet1!$D$2:$D$11=0),ROWS(A$2:A2))),"")
I2:K8I2=IFERROR(INDEX(Sheet2!A:A,AGGREGATE(15,6,ROW(Sheet2!$D$2:$D$11)/(Sheet2!$D$2:$D$11=0),ROWS(A$2:A2))),"")
N2:P3N2=FILTER(A2:C6&" <- sheet1 sheet2->"&Sheet2!A2:C6,A2:A6&B2:B6&C2:C6<>Sheet2!A2:A6&Sheet2!B2:B6&Sheet2!C2:C6)
D2:D6D2=COUNTIFS(Sheet2!$A$2:$A$6,A2,Sheet2!$B$2:$B$6,B2,Sheet2!$C$2:$C$6,C2)
Dynamic array formulas.




Book4
ABCD
1Data1Data2Data3Helper
21aa1
32bb1
43ac0
54dc1
65ee0
Sheet2
Cell Formulas
RangeFormula
D2:D6D2=COUNTIFS(Sheet1!$A$2:$A$6,A2,Sheet1!$B$2:$B$6,B2,Sheet1!$C$2:$C$6,C2)


the dropbox link will be around a few days only
 
Upvote 0
Try:
VBA Code:
Sub Test()
  Dim myArr1 As Variant, myArr2 As Variant
  myArr1 = Worksheets("Sheet1").UsedRange
  myArr2 = Worksheets("Sheet2").UsedRange
  
  For r = 1 To Worksheets("Sheet1").UsedRange.Rows.Count
    For c = 1 To Worksheets("Sheet1").UsedRange.Columns.Count
      If myArr2(r, c) <> myArr1(r, c) Then
        Worksheets("Sheet2").Cells(r, c).Interior.ColorIndex = 3
      End If
    Next
  Next
End Sub
 
Upvote 0
Try:
VBA Code:
Sub Test()
  Dim myArr1 As Variant, myArr2 As Variant
  myArr1 = Worksheets("Sheet1").UsedRange
  myArr2 = Worksheets("Sheet2").UsedRange
 
  For r = 1 To Worksheets("Sheet1").UsedRange.Rows.Count
    For c = 1 To Worksheets("Sheet1").UsedRange.Columns.Count
      If myArr2(r, c) <> myArr1(r, c) Then
        Worksheets("Sheet2").Cells(r, c).Interior.ColorIndex = 3
      End If
    Next
  Next
End Sub
it ended up with an error "run-time error 9 subscript out of range"

further its highlighting cells not the rows ... requirement is to compare rows of two sheets and get the differences
 
Upvote 0
if you wanted VBA , cant help - but can be done with a formula and some helper columns
IFERROR(INDEX(Sheet1!A:A,AGGREGATE(15,6,ROW(Sheet1!$B$2:$B$11)/(Sheet1!$B$2:$B$11=0),ROWS(A$2:A2))),"")

or using filter - with NO helper columns - But i dont think 2019 version has the FILTER() function
=FILTER(A2:C6&" <- sheet1 sheet2->"&Sheet2!A2:C6,A2:A6&B2:B6&C2:C6<>Sheet2!A2:A6&Sheet2!B2:B6&Sheet2!C2:C6)

Book4
ABCDEFGHIJKLMN
1Data1Data2Data3Helpersheet 1 extractsheet 2 extract
21aa13cv3ac3 <- sheet1 sheet2->3
32bb15ed5ee5 <- sheet1 sheet2->5
43cv0000000
54dc1000000
65ed0000000
7000000
8000000
Sheet1
Cell Formulas
RangeFormula
F2:H8F2=IFERROR(INDEX(Sheet1!A:A,AGGREGATE(15,6,ROW(Sheet1!$D$2:$D$11)/(Sheet1!$D$2:$D$11=0),ROWS(A$2:A2))),"")
I2:K8I2=IFERROR(INDEX(Sheet2!A:A,AGGREGATE(15,6,ROW(Sheet2!$D$2:$D$11)/(Sheet2!$D$2:$D$11=0),ROWS(A$2:A2))),"")
N2:P3N2=FILTER(A2:C6&" <- sheet1 sheet2->"&Sheet2!A2:C6,A2:A6&B2:B6&C2:C6<>Sheet2!A2:A6&Sheet2!B2:B6&Sheet2!C2:C6)
D2:D6D2=COUNTIFS(Sheet2!$A$2:$A$6,A2,Sheet2!$B$2:$B$6,B2,Sheet2!$C$2:$C$6,C2)
Dynamic array formulas.




Book4
ABCD
1Data1Data2Data3Helper
21aa1
32bb1
43ac0
54dc1
65ee0
Sheet2
Cell Formulas
RangeFormula
D2:D6D2=COUNTIFS(Sheet1!$A$2:$A$6,A2,Sheet1!$B$2:$B$6,B2,Sheet1!$C$2:$C$6,C2)


the dropbox link will be around a few days only
thanks for the response, you are right 2019 doesn't have filter ... tried other one but didn't work as well
 
Upvote 0
have two worksheets of data, each row is the same case on both sheets and the columns all contain the same variables I just need to know the differences between each row.
Based on your statement, the code considers both sheets consist of the same number of rows and columns.
 
Upvote 0
Ok try:
VBA Code:
Sub Test()
  For r = 1 To Worksheets("Sheet1").UsedRange.Rows.Count
    For c = 1 To Worksheets("Sheet1").UsedRange.Columns.Count
      If Worksheets("Sheet2").Cells(r, c) <> Worksheets("Sheet1").Cells(r, c) Then
        Worksheets("Sheet2").Cells(r, c).EntireRow.Interior.ColorIndex = 3
      End If
    Next
  Next
End Sub
 
Upvote 0
didn't work ... all rows got highlighted
Ok try:
VBA Code:
Sub Test()
  For r = 1 To Worksheets("Sheet1").UsedRange.Rows.Count
    For c = 1 To Worksheets("Sheet1").UsedRange.Columns.Count
      If Worksheets("Sheet2").Cells(r, c) <> Worksheets("Sheet1").Cells(r, c) Then
        Worksheets("Sheet2").Cells(r, c).EntireRow.Interior.ColorIndex = 3
      End If
    Next
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,540
Messages
6,125,405
Members
449,223
Latest member
Narrian

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