+ Reply to Thread
Results 1 to 7 of 7

VBA to compare two worksheets

  1. #1
    Forum Contributor
    Join Date
    01-16-2009
    Location
    Ill.
    MS-Off Ver
    Excel 2010
    Posts
    190

    VBA to compare two worksheets

    Hi all -- I have a task to compare and note any differences between two worksheets (maybe by color codes). Both sheets will be similar but not exact in reference to columns and rows. We have one report coming out of one reporting tool (SAS) and another coming from Cognos. We have many reports to compare. But for the sake of this post, say I'm comparing employee data...each reports shows Employee ID, Name, Title, Department, Manager, Salary...etc. One report may have Title in column D where the other may have it in J. I'm not sure really how to do this, with Vlookup but it also need to find it anywhere in the other sheet....hope this makes sense. That is why I was thinking something with VBA but I'm not sure where to get started.

    I'll have one workbook with two sheets, Sheet1 is Cognos, Sheet2 is SAS. I've included a test file with a few columns and rows...any suggestions would be great!! The actual files I'm working with can be from 100 rows and 10 columns to 15000 rows and 20 columns...As you'll see by my example, the column for Location is in column E and is called Physical Location, on the other sheet it's in column G and that is called Location_Desc. Again, another wrinkle in my task...Thanks to all for taking a look!
    Attached Files Attached Files

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA to compare two worksheets

    Hi Ironman,

    I may have something for you tomorrow - will there be other "reporting tools" and do you have a preferred order for the headers???
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA to compare two worksheets

    Hi Ironman,

    Paste the UDT portion up top just under the "Option Explicit"

    This will create a sheet that compares the "tools" over and under - take a look and let me know which discrepancies to treat and how to treat them

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA to compare two worksheets

    Hi Ironman,

    See if this is what you want - it list only the discrepancies, so no lone ID's are represented - it should be quick enough for 15K rows, but if you up the rows by a magnitude - we may need another paradigm

    Please Login or Register  to view this content.
    BTW you still need the UDT for this version.

    I decided to send the whole thing: HiresXP.xlsm
    Last edited by xladept; 03-23-2013 at 06:23 PM.

  5. #5
    Forum Contributor
    Join Date
    01-16-2009
    Location
    Ill.
    MS-Off Ver
    Excel 2010
    Posts
    190

    Re: VBA to compare two worksheets

    Hi xLadept - - Thanks for doing that. I'm not 100% why it's error'in out on

    Please Login or Register  to view this content.
    Specifically where it reads: .Cells(i,2): The example I attached was just that an example. I have many reports to validate and each has it's own set of columns/headers...reports can differ in columns as well as length, from 10 rows to 20,000. Columns can be A to M or A to AD...I do appreciate you putting in the time to send off the example file.

    Any other suggestions?

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA to compare two worksheets

    Have you got the UDT up top just under the option explicit - if so, then I'll need to see a sample workbook??

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA to compare two worksheets

    Attached two codes. First code shades color if the two sheets differ and second returns the differences on sheet called diff
    Attached Files Attached Files

+ 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.6.0 RC 1