+ Reply to Thread
Results 1 to 3 of 3

Comparing Two Sheets Using Key Field Column

  1. #1
    Registered User
    Join Date
    08-19-2011
    Location
    Middlesbrough, England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Comparing Two Sheets Using Key Field Column

    Hi all,

    I am trying to write a macro which will allow me to compare two excel sheets based on a column of key fields.

    What I have is a workbook containing two sheets. Column A is a column of key fields and data between the key fields in held in columns B:F.

    E,g, A1 is the unique key field, B1:F1 contains data relating to the key field.

    This key field exists in my secoind sheet but may not be in row 1, e.g. the key field in this example may be A4 (data relating to this key field in B4:F4).

    Subsiquently I need something that would start at cell A1 and 'search' through a defined range in column A of my second sheet in my workbook until it finds the matching key field in my first sheet. Then I would need to compare the B:F cells of the relative row and bold and italic any cells in that sheet.

    I was hoping some one would be able to point me in the right direction of how this would be achieved or possibly be able to share some code with me that can achieve this or something similar that I would be able to adapt.

    I have a small amount of VBA experience but I am trying to pick up as much as possible and have found it easier to learn when I have practicle examples of code to look at. I was thinking this would be achieved using arrays to match the key fields and then if statements like

    IF Activecell.row (< active cell being key field) column b <> sheet2.activecell.row ( < active cell being matched key field) column b
    set sheet2.activecell.row cell b bold = true

    ^^^ Above repeated for each column I want comparing. ^^^ I know the syntaxs are not correct (purely for explination).

    I could upload an example of what I am trying to achieve if further explination is required.

    Thank you in advance,

    Ben.

  2. #2
    Registered User
    Join Date
    08-19-2011
    Location
    Middlesbrough, England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Comparing Two Sheets Using Key Field Column

    No one with any ideas?

  3. #3
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Comparing Two Sheets Using Key Field Column

    Something like this? Please make a copy and test on your copy.

    Please Login or Register  to view this content.
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

+ 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