+ Reply to Thread
Results 1 to 14 of 14

Macro based on Primary key

  1. #1
    Registered User
    Join Date
    03-06-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    47

    Macro based on Primary key

    Hi,


    I have data in sheet1 and sheet2.It will comparesheet1 data with sheet2 data based on empid.If empid matches
    with sheet2 then chcek all the data for the empid whether it is matching or not.If any column values is mismatching for that particular id in sheet1 and sheet2
    then highlight those unmatched columns with red background in both the sheets.If empid not present in any sheet then highlight that entire record with red color background color.Output Highlighted in bold color below.Sheet1 and sheet2 have more number of columns not only 4 columns .but sheet1 and sheet2 have same number of columns.

    sheet1

    Empid name loc age
    1 a d 23
    2 b e 21
    3 c f 20
    4 d g 22
    5 e h 24
    6 f i 25

    sheet2
    Empid name loc age
    1 a d 23
    2 b e 21
    3 c f 20
    4 f g 22
    5 e k 24
    7 f j 26
    Last edited by aniletc37; 04-09-2014 at 09:19 AM.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro based on Primary key

    Hi aniletc37

    Place your Data in a Workbook then attach that Workbook.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    03-06-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro based on Primary key

    Hi jaslake,

    Please check the attached data for reference.I have added only 4 rows and 4 columns data for sample.But no of max columns should be 25 in sheet1 and sheet2. I need powerful macro because i'm having almost 250000 records in each sheet.So performance also one issue...
    Attached Files Attached Files

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro based on Primary key

    Hi aniletc37

    Performance IS going to be an issue...

  5. #5
    Registered User
    Join Date
    03-06-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    47
    Hi jaslake,

    Can you provide code for this.I will check with less number of records.If it is take time also noproblem.in between it shows like time for comparing msgbox also noproblem
    Last edited by aniletc37; 04-12-2014 at 11:32 AM.

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro based on Primary key

    Working on it....

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro based on Primary key

    Hi aniletc37

    This Code is in the attached and appears to do as you require...CTRL + x will fire the Code. Change Sheet Names as appropriate...
    Please Login or Register  to view this content.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    03-06-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro based on Primary key

    Hi jaslake,

    Thx for the code.If add more columns it is giving error and some extra coulmns are creating in sheet1 and sheet2 as processed with 'X' also It is giving run time error autofilter method of range class failed.6th record is not identifying in sheet2 also not showing green colorbcz it is not present in sheet1.Check the attached data for reference.

    Parameterization of columns is possible for this code.Like here we are considering Column A as key based on that we are checking data in sheet1 and sheet2.Instead of that while running macro it will ask for column name as Key to comapre in sheet1 and sheet2.if we give column numbers then it will comapre data based on those keys.
    Attached Files Attached Files

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro based on Primary key

    Hi aniletc37

    This Code handles Issue 1...had to change this line of Code
    Please Login or Register  to view this content.
    I'll need to think about Issue 2.
    Please Login or Register  to view this content.
    Last edited by jaslake; 04-13-2014 at 02:59 PM.

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro based on Primary key

    Hi aniletc37

    Regarding this...I have no clue what you want
    Parameterization of columns is possible for this code.Like here we are considering Column A as key based on that we are checking data in sheet1 and sheet2.Instead of that while running macro it will ask for column name as Key to comapre in sheet1 and sheet2.if we give column numbers then it will comapre data based on those keys
    Best I can tell you, try the attached. If it does not work you need to tell me why.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    03-06-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Macro based on Primary key

    Hi jaslake,

    Thx for the code.Is there any option to select multiple columnnames for comparing in userform?

  12. #12
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro based on Primary key

    Hi aniletc37

    I've written/rewritten the Code twice. Before I rewrite it again I'd like you to think and be clear about your needs. Identify and spell them out. Get back to me when you've done so.

  13. #13
    Registered User
    Join Date
    03-06-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    47
    Hi jaslake ,

    I'm ok with that code.I need only one help.forms are not enabled in my office system.can you just give the code with out using forms.you have provided last time that code is enough.only problem with last time code is columns are more its creating some extracolumns like processd with x and runtime error. just rectify that issue and provide the code.
    Last edited by aniletc37; 04-14-2014 at 06:59 PM.

  14. #14
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro based on Primary key

    Hi aniletc37

    I don't know...you'll need to tell me if it's working. As before, CTRL + x will fire the Code.
    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)

Similar Threads

  1. [SOLVED] Macro for primary and secondary Y axes based on cell values in another worksheet
    By jjtrip in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-04-2013, 03:21 PM
  2. Macro or VBA code to update non primary sheets based on checkbox
    By jbpar5s in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-02-2013, 06:19 PM
  3. [SOLVED] Combine multi-value rows into a single row based on a Primary Key
    By bocrad75 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-21-2013, 05:20 PM
  4. Updating two worksheets based on one primary one
    By tanj92 in forum Excel General
    Replies: 0
    Last Post: 07-07-2011, 10:15 PM
  5. macro help: click button to update value of primary cell
    By uthminister in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-24-2009, 10:46 AM

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