+ Reply to Thread
Results 1 to 4 of 4

Macro using VLOOKUP with multiple matches between multiple sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    07-27-2011
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    6

    Macro using VLOOKUP with multiple matches between multiple sheets

    I have a macro that compares data in Sheet1 Column B with Sheet2 Column C. If they match, the value in Sheet1 Column E is copied to Sheet2 Column D. Right now the macro only lists the first match and ignores any other matches after that. How do I modify the macro to include all matches in one long string (separated by spaces)?

    [code]
    Sub PlaceVLookupTMS()
    ' place in a standard module
    With Sheets("Sheet2")
    .Range("D2:D" & .Range("A" & .Rows.Count).End(xlUp).Row).FormulaR1C1 = _
    "=IFERROR(VLOOKUP(RC[-1],Sheet1!C[-2]:C[1],4,FALSE),"""")"
    End With
    End Sub
    [code]
    Attached Files Attached Files

  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: Macro using VLOOKUP with multiple matches between multiple sheets

    1) fix that [/code] tag at the end above...

    2) In your sample sheet, how about some sample results?
    _________________
    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!)

  3. #3
    Registered User
    Join Date
    07-27-2011
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Macro using VLOOKUP with multiple matches between multiple sheets

    Sorry about that. Attached are the results of the macro. If you see in Sheet 2 D1, the IBC number only comes back with the first result which is 234823WUIA and fails to display 21232123 which also matches. Any clues on how to modify the macro? Thanks in advance for your help!

    Sub PlaceVLookupTMS()
    ' place in a standard module
    With Sheets("Sheet2")
    .Range("D2:D" & .Range("A" & .Rows.Count).End(xlUp).Row).FormulaR1C1 = _
    "=IFERROR(VLOOKUP(RC[-1],Sheet1!C[-2]:C[1],4,FALSE),"""")"
    End With
    End Sub
    Attached Files Attached Files

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

    Re: Macro using VLOOKUP with multiple matches between multiple sheets

    Hehe, sorry I'm so vague. Please post examples of your expected results, not the results of your current macro.

+ 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