+ Reply to Thread
Results 1 to 5 of 5

Macro formula to match two columns and Produce result in fourth column.

  1. #1
    Registered User
    Join Date
    04-29-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    2

    Macro formula to match two columns and Produce result in fourth column.

    Hi,
    I'm a newbee in Excel programming and macros. I need help creating a Macro formula to match two columns (A & C) and if there's a match, I want it to produce the value that's in column B(right next to column C), into column D. I tried using Vlookup but no luck. So need excel macro code.
    Please find sample attached.
    Note : All the values will be basically text and not numbers.(in sample you may find some numbers)

    Thanks for your help & time.

    Awaiting your response back.

    Regards,
    Roger
    Attached Files Attached Files

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

    Re: Macro formula to match two columns and Produce result in fourth column.

    I'm confused. Did you supply the "D" column values in the sample to show what the result of a to-be-produced macro would achieve? As it stands in the sample workbook, I cannot find the logic necessary to address your request. Please clarify.
    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".

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: Macro formula to match two columns and Produce result in fourth column.

    add this to D1, and copy down. I assumed that if there was no match, you would no want to show anything.

    =IF(ISERROR(VLOOKUP(C1,$A$1:$B$11,2,FALSE)),"",VLOOKUP(C1,$A$1:$B$11,2,FALSE))

    if you do want to show something for a non-match, use this...

    =IF(ISERROR(VLOOKUP(C1,$A$1:$B$11,2,FALSE)),"whatever-you-want-to-show",VLOOKUP(C1,$A$1:$B$11,2,FALSE))
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Registered User
    Join Date
    04-29-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Macro formula to match two columns and Produce result in fourth column.

    Hi Alvarosiza - Yes. You are correct. Column D values are the values I'm trying to achieve.

    FDibbins - I tried your formula. But they are not maching my original column D values.

    Please advise.

    Once again thanks for your support. Appreciate it.

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: Macro formula to match two columns and Produce result in fourth column.

    thats because you had double entries for "chips", which cavlue would you want matched? the others all match because there is only 1 instance of the "item"

    see the attached...
    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