+ Reply to Thread
Results 1 to 4 of 4

Need VBA code to compare two sheets

  1. #1
    Registered User
    Join Date
    05-12-2014
    MS-Off Ver
    Excel 2003
    Posts
    2

    Need VBA code to compare two sheets

    Hi Experts,

    I am a newbie to excel, need to compare sheet1 and sheet2 for multiple columns and place the result in sheet4.

    * All the column name in sheet1 are not identical to sheet2.
    * column names in sheet1 and sheet2 are related using the mapping given in sheet3.

    The below is the example scenario

    Sheet1
    NAME DOJ PROFILE_CREATE_DATE Location id LAN
    David 2013-12-31 2014-02-01 09:34:00 UK 125016 dmill2
    Yu 2014-01-01 2014-02-17 09:34:00 CHINA 184217 yxin2
    Smith 2014-01-02 2014-01-25 09:34:00 India 42876 spatel1
    Sam 2014-01-03 2014-01-21 09:34:00 USA 16742 sander1

    Sheet2
    e_id location LAN NAME PROFILE_DATE
    125016 UK dmill2 David 2014-02-01 09:34:00
    184217 CHINA yxin2 Yu 2014-02-17 09:34:00
    42876 India spatel1 Smith 2014-01-25 09:34:00
    16742 USA sander1 Sam 2014-01-21 09:34:00

    Sheet3
    Sheet1 Sheet2
    NAME NAME
    LOCATION LOCATION
    DOJ NULL
    PROFILE_CREATE_DATE PROFILE_DATE
    ID E_ID
    LAN LAN


    Now i need the output in sheet4 as below

    NAME DOJ PROFILE_CREATE_DATE Location id LAN
    TRUE N/A TRUE TRUE TRUE TRUE
    TRUE N/A TRUE TRUE TRUE TRUE
    TRUE N/A TRUE TRUE TRUE TRUE
    TRUE N/A TRUE TRUE TRUE TRUE

    For this firstly,i need to replace all the column names in sheet2 as per mapping in sheet3.
    For ex: column name e_id in sheet2 should be renamed to ID

    Secondly match sheet1 and sheet2, then write the result in sheet4.

    Moreover, this should be the routine task for me and every time number of columns changes. Sometimes number of columns would be 500.

    Could you please help/guide me to fix this?

    Thanks,
    Gokul

  2. #2
    Forum Contributor lancer102rus's Avatar
    Join Date
    04-02-2014
    Location
    Ufa
    MS-Off Ver
    Excel 2010, 2013
    Posts
    252

    Re: Need VBA code to compare two sheets

    See the attachment

    compareSheets.xlsm

  3. #3
    Registered User
    Join Date
    05-12-2014
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Need VBA code to compare two sheets

    Excellent. Many Thanks for the code.

    I can see one discrepancy in this.

    In sheet4(output sheet), For column-name(PROFILE_CREATE_DATE) data is wrongly mapped to column Location in sheet1 and sheet2.

    This is due to order of column name in Sheet3 and sheet1 are different.

    is it possible to modify the code to handle even the column name in sheet3 are of different order.

    Again Thank you for the help.

  4. #4
    Forum Contributor lancer102rus's Avatar
    Join Date
    04-02-2014
    Location
    Ufa
    MS-Off Ver
    Excel 2010, 2013
    Posts
    252

    Re: Need VBA code to compare two sheets

    Sory.
    Just repalce
    Please Login or Register  to view this content.
    by
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    replace by
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. compare code in two sheets
    By cmccabe in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-10-2014, 02:29 PM
  2. [SOLVED] Code to compare data in 2 sheets and delete duplicates
    By amar05 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-13-2013, 03:24 PM
  3. [SOLVED] Need micro compare code in sheet2 and sheet3 with code in sheet1
    By jamalmail in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-21-2013, 05:15 PM
  4. Compare sheets
    By Huw Wales in forum Excel General
    Replies: 2
    Last Post: 09-17-2011, 07:12 PM
  5. Excel 2007 : compare sheets
    By rajeshkumawat in forum Excel General
    Replies: 1
    Last Post: 07-05-2009, 01:33 PM

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