Compare 2 columns in one worksheet to another

Kinez101

New Member
Joined
Oct 18, 2016
Messages
23
I have a file with over 100K rows and was wondering if there is a quick way to compare columns C and D in Previous Month to Current Month and vice-versa then output differences to Differences worksheet.
 
PQ is part of Excel in versions 2010 and later. In 2016, it is part of Excel and does not require a download. It is called Get and Transform. Otherwise, download it. It may take several days for me to build a VBA solution as I am in the midst of relocating from my summer house to winter house and time is not abundant. Can you upload to a third party some sample worksheets for each month as I don't wish to try and reconstruct your data. This is necessary in order to test.
 
Last edited:
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Maybe something like this:
Excel Workbook
ABCDEFGHI
1List 1List 2List 1 not in List 2
2BIC CODEBRANCH CODEBIC CODEBRANCH CODEBIC CODEBRANCH CODE
3AAAARSBGXXXAAAARSBGXXXAAAMFRP1XXX
4AAACKWKWXXXAAACKWKWXXXAABAFI22TMS
5AAADFRP1XXXAAADFRP1XXX
6AAAGFRP1XXXAAAGFRP1XXX
7AAAJBG21XXXAAAJBG21XXX
8AAALSARIALKAAALSARIALK
9AAALSARICTDAAALSARICTD
10AAALSARIJEDAAALSARIJED
11AAALSARIRYDAAALSARIRYDList 2 not in List 1
12AAALSARIXXXAAALSARIXXXAAAMFRP1TTT
13AAAMFRP1XXXAAAMFRP1TTTAABAFI23TMS
14AAAOFRP1XXXAAAOFRP1XXX
15AAAPBGS1XXXAAAPBGS1XXX
16AAASTHB1XXXAAASTHB1XXX
17AABAFI22TMSAABAFI23TMS
18AABAFI22XXXAABAFI22XXX
19AABASESSTMSAABASESSTMS
20AABASESSXXXAABASESSXXX
21AABMIT22XXXAABMIT22XXX
Sheet
 
Upvote 0
This code is great start, just need it modified to read Column C and D between 2 sheets and not loop through 100K rows of data:
Code:
Option Explicit
Sub CompareYesterdayTodayV2()
' stanleydgromjr, 08/09/2011
' http://www.excelforum.com/excel-programming/785472-compare-two-worksheets-and-present-differences-in-a-third.html
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("Previous Month")
Set wT = Worksheets("Current Month")
Set wC = Worksheets("Differences")
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("C2", wY.Range("C" & 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("C" & 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("C2", wT.Range("C" & 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("C" & 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("C2", wY.Range("C" & 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
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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