+ Reply to Thread
Results 1 to 6 of 6

Thread: Compare two worksheets

  1. #1
    Registered User
    Join Date
    10-23-2011
    Location
    Lahore, Punjab
    MS-Off Ver
    Excel 2007
    Posts
    7

    Compare two worksheets

    Hello every body

    How can I compare two different sheets or ranges in same files or different files.
    Last edited by Farooque; 11-03-2011 at 02:00 PM.

  2. #2
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,371

    Re: Compare two worksheets

    There should be some common field or fields on the basis of which you can compare. Probably if you attach a sample file(s), i can help better.

  3. #3
    Registered User
    Join Date
    10-23-2011
    Location
    Lahore, Punjab
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Compare two worksheets

    Dear
    Both sheet having same format, only data changed
    sample is attached
    Attached Files Attached Files

  4. #4
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,371

    Re: Compare two worksheets

    So as per the attached files, what do you want to compare? Each and every data? Also, if we find a mismatch, what should be done?

  5. #5
    Registered User
    Join Date
    10-23-2011
    Location
    Lahore, Punjab
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Compare two worksheets

    Sorry for too much delay, I want to check changes (if any) in todays sheet comparing with yesterdays sheet. Todays sheet may highlight the changes in a seperate sheet or any other function which shows the changes

    Waiting your useful feedback
    Thanks

  6. #6
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,371

    Re: Compare two worksheets

    This code brings out the differences between Summery and Summery (2). The differences are highlighed in the Results tab. Is this what you are looking for?
    Sub compare_sheets()
    
    Dim str As String
    Dim cRow As Integer
    
    Sheets("Summery").Range("A2:Z3").Copy Sheets("Results").Range("A1")
    
    With Sheets("Summery")
        For cRow = 4 To .Range("A" & .Rows.Count).End(xlUp).Row
            str = str & Join(Application.Transpose(Application.Transpose(.Cells(cRow, 1).Resize(1, 26))), "|") & "~"
        Next
    End With
    With Sheets("Summery (2)")
        For cRow = 4 To .Range("A" & .Rows.Count).End(xlUp).Row
            If InStr(1, str, Join(Application.Transpose(Application.Transpose(.Cells(cRow, 1).Resize(1, 26))), "|") & "~", vbTextCompare) = 0 Then
                .Cells(cRow, 1).Resize(1, 26).Copy
                lrow = Sheets("Results").Range("B" & Rows.Count).End(xlUp).Row
                Sheets("Results").Range("A" & lrow + 1).PasteSpecial
            End If
        Next
    End With
    
    End Sub
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0