Consulting

Results 1 to 7 of 7

Thread: Need to compare 2 very large worksheets

  1. #1

    Need to compare 2 very large worksheets

    We use SAP at work. In order to generate some of our reports, we export some very large List Edits to Excel Spreadsheets and then link them into MS Access. Every day we export about 30,000 records.

    On a day to day basis, I need to know "what" has changed from one day to the next. In reality, I am now looping through the Work Order column of one and then trying to find it in the Work Order of the other.

    Is there a way of "comparing" one worksheet to another and then marking the cells that are different?

    I am just getting started on this project and will be adding more ideas and questions to the Access page.
    ttfn

    Kicker

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Got an example workbook with 100-200 samples?

    Paul

  3. #3
    Here is a quick mock up. In reality, there are over 20,000 rows and more than 30 columns for each file. Ignoring all other items, I need to determine.

    1. are there any records in Sheet 1 that are not in Sheet 2?
    2. are there any records in Sheet 2 that are not in Sheet 1?
    3. Are any of the records different. For example if Col C has changes, I need to know about it.

    Thanks.
    ttfn

    Kicker

  4. #4
    VBAX Expert
    Joined
    Feb 2005
    Location
    Nanaimo, British Columbia, Cananda
    Posts
    568
    Location
    Hi K,

    Can you post the code you're using? Maybe we can speed it up!
    Cheers,

    dr

    "Questions, help and advice for free, small projects by donation. large projects by quote"

    http:\\www.ExcelVBA.joellerabu.com

  5. #5
    VBAX Regular
    Joined
    Jun 2009
    Posts
    24
    Location
    I am not sure if this helps, however this was passed to me and works quite well.

    You may be able to use it.


    [vba]
    Sub Compare()
    Dim rCell As Range
    Dim rRng As Range
    Dim wksRetain As Worksheet
    Dim wksToCheck As Worksheet
    Const WKS_ORIG As String = "Sheet1" '<---Change names to suit
    Const WKS_COPY As String = "Sheet2"

    Set rRng = ThisWorkbook.Worksheets(WKS_ORIG).Range("A1:Z100") 'this can be any range you need

    With ThisWorkbook.Worksheets(WKS_COPY)

    For Each rCell In rRng

    If Not rCell.Value = .Range(rCell.Address).Value _
    And Not .Range(rCell.Address).Value = vbNullString Then


    rCell.Value = rCell.Value & Chr(10) & "DATACHANGE" & Chr(10) & Format(Date, "MM/DD/YY") _
    & Chr(10).Range(rCell.Address).Value & _
    Chr(10)
    End If
    Next
    End With
    End Sub
    [/vba]

    Kind Regards

    Champers

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    I made a few minor tweaks to consider. I just shaded the cells for testing, but you can replace that code.

    But, the big question I have is that there seems to be an assumption in your code that the Order# are 1-1 between the two sheets, e,g, Sheet1 A56 = 800011204, but Sheet2 A56 = 800011205.

    To mark the Adds and Deletes will take a little more work.

    Let me know if that's what you're looking for. I have code to do that and I can make it compatible with your data if you want. I pulled it out into a seperate WB but you can use it as a starting point if you want. NOTE: I have my share of assumptions and preferences built into this also

    There's a macro button on Sheet1 to launch a Form, and it makes a Comparision sheet

    [vba]

    Sub Compare()
    Dim rCell As Range
    Dim rRng As Range
    Dim wksRetain As Worksheet
    Dim wksToCheck As Worksheet
    Const WKS_ORIG As String = "Sheet1" '<---Change names to suit
    Const WKS_COPY As String = "Sheet2"


    Set wksToCheck = Worksheets(WKS_COPY)

    Set rRng = ThisWorkbook.Worksheets(WKS_ORIG).Cells(1, 1).SpecialCells(xlCellTypeConstants)
    For Each rCell In rRng
    With rCell
    If .Value <> wksToCheck.Cells(.Row, .Column).Value Then
    .Interior.ColorIndex = 3 ' just for testing
    End If
    End With
    Next
    End Sub
    [/vba]

    Of couse, if you find any problems, I'd like to hear so that I can fix mine

    Paul

  7. #7
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Are order numbers unique on each sheet?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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