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​
 
It must be based on something like an ID number on the first column. Otherwise there Is a probability that every row is different from one another.
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
data has more columns however reconciliation shall be based on these four columns as required, if you can assist to do the matching based on these four columns
 
Upvote 0
VBA Code:
Sub Test()
  With Application
  For i = 1 To Worksheets("Sheet1").UsedRange.Rows.Count
    For j = 1 To Worksheets("Sheet2").UsedRange.Rows.Count
      If Worksheets("Sheet2").Cells(j, 1) = Worksheets("Sheet1").Cells(i, 1) Then
        If Join(.Transpose(.Transpose(Worksheets("Sheet2").Rows(j).Value)), Chr(0)) <> Join(.Transpose(.Transpose(Worksheets("Sheet1").Rows(i).Value)), Chr(0)) Then
          Worksheets("Sheet2").Rows(j).EntireRow.Interior.ColorIndex = 3
        End If
      End If
    Next
  Next,
  End With
End Sub
This code considers column A is the identifier for both sheets.
 
Upvote 0
getting following error;

compile error:

syntax error
VBA Code:
Sub Test()
  With Application
  For i = 1 To Worksheets("Sheet1").UsedRange.Rows.Count
    For j = 1 To Worksheets("Sheet2").UsedRange.Rows.Count
      If Worksheets("Sheet2").Cells(j, 1) = Worksheets("Sheet1").Cells(i, 1) Then
        If Join(.Transpose(.Transpose(Worksheets("Sheet2").Rows(j).Value)), Chr(0)) <> Join(.Transpose(.Transpose(Worksheets("Sheet1").Rows(i).Value)), Chr(0)) Then
          Worksheets("Sheet2").Rows(j).EntireRow.Interior.ColorIndex = 3
        End If
      End If
    Next
  Next,
  End With
End Sub
This code considers column A is the identifier for both sheets.
etting
 
Upvote 0
do you want to extract the differences - as i should with Aggregate formulas - to show difference of sheet1 and sheet2 with a helper columns

VBA would not need the helper columns - and a better solution

But here is the conditional formatting

Book6
ABCDEFGHIJKLM
1Data1Data2Data3Helpersheet 1 extractsheet 2 extract
21aa13cv3ac0
32bb15ed5ee0
43cv00000000
54dc10000000
65ed00000000
70000000
80000000
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))),"")
J2:M8J2=IFERROR(INDEX(Sheet2!A:A,AGGREGATE(15,6,ROW(Sheet2!$D$2:$D$11)/(Sheet2!$D$2:$D$11=0),ROWS(A$2:A2))),"")
D2:D6D2=COUNTIFS(Sheet2!$A$2:$A$6,A2,Sheet2!$B$2:$B$6,B2,Sheet2!$C$2:$C$6,C2)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:D6Expression=COUNTIFS(Sheet2!$A$2:$A$6,$A2,Sheet2!$B$2:$B$6,$B2,Sheet2!$C$2:$C$6,$C2)=0textYES
 
Upvote 0
There is a comma left after Next. Please try again:
VBA Code:
Sub Test()
  With Application
  For i = 1 To Worksheets("Sheet1").UsedRange.Rows.Count
    For j = 1 To Worksheets("Sheet2").UsedRange.Rows.Count
      If Worksheets("Sheet2").Cells(j, 1) = Worksheets("Sheet1").Cells(i, 1) Then
        If Join(.Transpose(.Transpose(Worksheets("Sheet2").Rows(j).Value)), Chr(0)) <> Join(.Transpose(.Transpose(Worksheets("Sheet1").Rows(i).Value)), Chr(0)) Then
          Worksheets("Sheet2").Rows(j).EntireRow.Interior.ColorIndex = 3
        End If
      End If
    Next
  Next
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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