Results 1 to 4 of 4

Find differences between 2 excel sheets or tables

Threaded View

  1. #1
    Registered User
    Join Date
    02-19-2015
    Location
    Calgary
    MS-Off Ver
    2010
    Posts
    3

    Find differences between 2 excel sheets or tables

    Hi,

    I am trying to find differences between 2 super large excel sheets. I have a table in Sheet 1 and an almost identical table in Sheet 2. Sheet 2's table has cells with changed or deleted values though. I want to highlight or know about changes between Sheet 2 and 1. I found the excel VBA code below on the internet:

    Sub RunCompare()
    
    Call compareSheets("Sheet1", "Sheet2")
    
    End Sub
    
    
    Sub compareSheets(shtSheet1 As String, shtSheet2 As String)
    
    Dim mycell As Range
    Dim mydiffs As Long
    
    'For each cell in sheet2 that is not the same in Sheet1, color it yellow
    For Each mycell In ActiveWorkbook.Worksheets(shtSheet2).UsedRange
        If Not mycell.Value = ActiveWorkbook.Worksheets(shtSheet1).Cells(mycell.Row, mycell.Column).Value Then
            
            mycell.Interior.Color = vbYellow
            mydiffs = mydiffs + 1
            
        End If
    Next
    
    'Display a message box to demonstrate the differences
    MsgBox mydiffs & " differences found", vbInformation
    
    ActiveWorkbook.Sheets(shtSheet2).Select
    
    End Sub
    It almost works. The problem is that it highlights way too many cells whenever a row in Sheet 2 will have disappeared compared to Sheet 1. The code above compares the 2 sheets with respect to the content of cells relative to their position in the sheet (e.g. Cell B18 in Sheet 1 == Cell B18 in Sheet 2??). I would like it to compare the values in the 2 tables based on the ID number in the very left column of both tables. That way, if a row is deleted in the table from sheet 1 to sheet 2, I will not have all cells highlighted in Sheet 2 from that deleted row downwards.

    I attached a simplified version of my excel sheet tables. The real one has thousands of rows. test1.xlsm

    Thanks!

    FBG
    Last edited by FDibbins; 02-19-2015 at 06:33 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Need formula or Macro to help find differences between two tables of data
    By geckony in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-08-2014, 05:27 AM
  2. Find Differences between columns sheets
    By dalerdd in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-02-2013, 02:44 PM
  3. how to find differences between 2 excel sheets
    By remdog in forum Excel General
    Replies: 7
    Last Post: 09-11-2012, 07:16 AM
  4. Macro to find differences between 2 sheets based on cells matching
    By mauricio1013 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-27-2012, 04:03 PM
  5. Replies: 1
    Last Post: 07-12-2012, 05:43 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1