+ Reply to Thread
Results 1 to 2 of 2

Matching column values in 2 sheets and copying another column over if match

  1. #1
    Registered User
    Join Date
    08-20-2012
    Location
    NC
    MS-Off Ver
    Excel 2010
    Posts
    1

    Matching column values in 2 sheets and copying another column over if match

    Hi folks,

    I'm very inexperienced in writing macros and using Excel in general and am quite frustrated with trying to accomplish what seems like it should be relatively simple.

    Here is the situation. I have two spreadsheets in one workbook (Excel 2010) which I want to compare and modify with a macro. Both spreadsheets are product lists for an ecommerce site - Sheet1 is a database dump of all fields and Sheet2 is a human-made excel file that has additional data for a subset of the things in Sheet1.

    Basically, Sheet1 is a full list of about 3000 products and all of their information and details. Sheet2 is a list of about 600 of the products listed in Sheet1, and only has specific details like product description and category (and not the other few dozen database fields/columns that are in Sheet1. I need to update a specific column in the master product list (Sheet1) with the data in a specific column from the subset (Sheet2) for all matches (Sheet1 column A is a unique identifier that is found also in Sheet2 Column B). In real terms, sheet2 has updated product descriptions for 600 of the products in sheet1 and I want to overwrite/update them but not disturb anything else. That way I will update the product descriptions for the 600 products in Sheet1 that are found in Sheet2, and I can reimport the full 3000 product database back into the ecommerce platform complete with the 600 updated descriptions.

    The logic is as follows, for the entirety of SHeet1:

    When Sheet1 Column A is equal to Sheet2 Column B (these are the unique product identifiers / SKUs) then:
    Take value of Sheet2 Column F (product description) and copy it to Sheet1 Column P (product description), overwriting anything that was already in Sheet1 Column P (but ONLY for rows where Sheet1 Column A = Sheet2 Column B, otherwise Sheet1 Column P should remain unchanged).

    I hope this is relatively clear. I have been struggling with this all day and I would really appreciate one of you VBA gurus' help! Thanks so much!
    Last edited by JBeaucaire; 08-20-2012 at 06:49 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Matching column values in 2 sheets and copying another column over if match

    You can do this without a macro pretty easily. Since you didn't upload a sample workbook, I'll have to describe and you will adapt it:

    1) Assume the matching data is in column A of both sheets
    2) Assume column B on sheet1 you want to update with colum D of sheet2
    3) In an empty column of sheet1, put in this formula, let's say you put in in Z2:

    =IFERROR(VLOOKUP($A2, Sheet2!$A:$B, 2, 0), $B2)

    4) Copy that formula down the helper column and you will get a new list that has either then NEW value from sheet2, or when there is no match, the existing value from column B of that row.

    5) Copy the new set of data cells

    6) Click on the original data at B2 and do a Paste > Paste Special > Values. That moves the new data into column B permanently

    7) repeat above steps for other columns, editing the formula to VLOOKUP the same values in column A, but adjusting to return values from other columns of sheet2.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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