hi,
i need to compare 2 sheets of data and have the differences on the 3rd which is usually easy enough but i need to compare more then just one data to another.
i need to look up an account number on each sheet and then compare the data that relates to that specific account (value, rate, date) in the columns next to it.
on the 3rd sheet i want to display the accounts that have differences and also all info for accounts that appear on one sheet and not the other
anyone have any ideas?
i have found the below code which is close but it does not seem to work properly as it ends up showing matches on the 3rd sheet.
note: this is a cross post from:
Comparing Data based on number found
was getting no love so i thought id post here too
i need to compare 2 sheets of data and have the differences on the 3rd which is usually easy enough but i need to compare more then just one data to another.
i need to look up an account number on each sheet and then compare the data that relates to that specific account (value, rate, date) in the columns next to it.
on the 3rd sheet i want to display the accounts that have differences and also all info for accounts that appear on one sheet and not the other
anyone have any ideas?
i have found the below code which is close but it does not seem to work properly as it ends up showing matches on the 3rd sheet.
Code:
Option Explicit
Sub CompareYesterdayTodayV2()
Dim wY As Worksheet, wT As Worksheet, wC As Worksheet
Dim c As Range, FR As Long, NR As Long, cc As Long, dd As Long, NC As Long, LC As Long
Application.ScreenUpdating = False
Set wY = Worksheets("sheet1")
Set wT = Worksheets("sheet2")
Set wC = Worksheets("sheet3")
wC.UsedRange.Clear
LC = wT.Cells(1, Columns.Count).End(xlToLeft).Column
wY.Range(wY.Cells(1, 1), wY.Cells(1, LC)).Copy wC.Range("A1")
For Each c In wY.Range("B2", wY.Range("B" & Rows.Count).End(xlUp))
FR = 0
On Error Resume Next
FR = Application.Match(c, wT.Columns(2), 0)
On Error GoTo 0
If FR = 0 Then
NR = wC.Range("B" & wC.Rows.Count).End(xlUp).Offset(1).Row
wY.Range(wY.Cells(c.Row, 1), wY.Cells(c.Row, LC)).Copy wC.Range("A" & NR)
wC.Range("A" & NR).Resize(, LC).Interior.Color = 255
End If
Next c
For Each c In wT.Range("B2", wT.Range("B" & Rows.Count).End(xlUp))
If c <> "" Then
FR = 0
On Error Resume Next
FR = Application.Match(c, wY.Columns(2), 0)
On Error GoTo 0
If FR = 0 Then
NR = wC.Range("B" & wC.Rows.Count).End(xlUp).Offset(1).Row
wT.Range(wT.Cells(c.Row, 1), wT.Cells(c.Row, LC)).Copy wC.Range("A" & NR)
wC.Range("A" & NR).Resize(, LC).Interior.Color = 65280
End If
End If
Next c
For Each c In wY.Range("B2", wY.Range("B" & Rows.Count).End(xlUp))
If c <> "" Then
FR = 0
On Error Resume Next
FR = Application.Match(c, wT.Columns(2), 0)
On Error GoTo 0
If FR <> 0 Then
NR = wC.Range("B" & wC.Rows.Count).End(xlUp).Offset(1).Row
NC = 0
For cc = 3 To LC Step 1
If wY.Cells(c.Row, cc) <> wT.Cells(FR, cc) Then NC = NC + 1
Next cc
If NC = LC Then
wC.Cells(NR, 1).Resize(, 2).Value = wY.Cells(c.Row, 1).Resize(, 2).Value
For dd = 3 To LC Step 1
With wC.Cells(NR, dd)
.NumberFormat = "@"
.Value = wY.Cells(c.Row, dd).Value & "/" & wT.Cells(FR, dd).Value
End With
Next dd
wC.Range("C" & NR).Resize(, LC).Interior.Color = 65535
ElseIf NC > 0 And NC < LC Then
wC.Cells(NR, 1).Resize(, 2).Value = wY.Cells(c.Row, 1).Resize(, 2).Value
For cc = 3 To LC Step 1
If wY.Cells(c.Row, cc) <> wT.Cells(FR, cc) Then
With wC.Cells(NR, cc)
.NumberFormat = "@"
.Value = wY.Cells(c.Row, cc).Value & "/" & wT.Cells(FR, cc).Value
.Interior.Color = 65535
End With
End If
Next cc
End If
End If
End If
Next c
wC.UsedRange.Columns.AutoFit
wC.Activate
Application.ScreenUpdating = True
End Sub
note: this is a cross post from:
Comparing Data based on number found
was getting no love so i thought id post here too