Comparing Data based on number found

tbar05

Board Regular
Joined
Jun 21, 2012
Messages
87
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.


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
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,215,754
Messages
6,126,681
Members
449,328
Latest member
easperhe29

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