+ Reply to Thread
Results 1 to 5 of 5

Match+Index or Vlookup with 2 columns as look up value? - VBA Loops (With Example)

  1. #1
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Match+Index or Vlookup with 2 columns as look up value? - VBA Loops (With Example)

    Hi all,

    Example sheet below!

    I'm trying to set up a Match+Index or Vlookup loop with VBA to return Countries for First and Last names, if the Country cell is empty.

    In the example:

    There is Sheet1 and Sheet2.
    On Sheet1 there is a table called DataTable, with First Names, Last Names and Countries, but for some names, the country cell is empty.
    On Sheet2 there is another table called AidTable, and it also has First Names, Last Names and Countries and in that one, all the countries are there for all the names, but not all the names are there.

    So I think I would need a loop, to go through the DataTable, and if the Country cell is not empty, then next loop, if the country cell is empty, then enter another loop, that loops through the Aid table and finds the same First Name - Last Name combination, and returns the country from the Aid table to the Data table.

    The twist is that the First Names and Last Names are written correctly in the DataTable, but in the AidTable they are separated wrong.
    (eg: First Name in DataTable: Adam Piotr Last Name in DataTable: Wrobel
    First Name in AidTable: Adam Last Name in AidTable: Piotr Wrobel)

    Practically I have a lookup table for the countries its just that the lookup value is in 2 columns, and they should be joined in a way that excel recognizes that they are the same thing.

    If possible to solve without helper columns that would be the best!

    Could someone help please?

    Question posted on Mr.ExcelMessage board: https://www.mrexcel.com/forum/excel-...ml#post5231293
    Attached Files Attached Files
    Last edited by LIL2606; 02-22-2019 at 09:48 AM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Match+Index or Vlookup with 2 columns as look up value? - VBA Loops (With Example)

    What have you got against helper columns?

    It seems to me that the simplest approach is a helper column in each table that concatenates the lastname & first name. Then use the INDEX(MATCH()) formula.

    Is there a reason why you've posted this in the programming/macros sub forum?
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: Match+Index or Vlookup with 2 columns as look up value? - VBA Loops (With Example)

    Yes, I posted this in the macros and VBA section because I am working on a project that requires me to solve this problem with VBA. I'm working on a data-converter
    which will be used by other users, so they just have to press a button and from the raw data they get a formatted and filtered data set that they can use for reports.

    I don't like helper columns because it makes a (possibly) 1 step process into a 3 steps process. 1 Create helper column 2 Do the thing 3 Delete helper column.
    I just find it inefficient. Its a personal grudge.

  4. #4
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,742

    Re: Match+Index or Vlookup with 2 columns as look up value? - VBA Loops (With Example)

    Should works:

    Please Login or Register  to view this content.
    EDIT: Hmm, it's working. I've added additional space, be sure that You are trying fixed version.
    Last edited by KOKOSEK; 02-22-2019 at 10:51 AM.
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  5. #5
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: Match+Index or Vlookup with 2 columns as look up value? - VBA Loops (With Example)

    Thank you very much for that, I rewrote it in my dialect a bit, but it was super helpful!

+ 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] Matching data from 2 columns VLOOKUP or INDEX:MATCH
    By Crawfy in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-28-2018, 08:18 PM
  2. [SOLVED] Index match or Vlookup multiple columns
    By geliedee in forum Excel General
    Replies: 6
    Last Post: 04-10-2015, 02:14 PM
  3. Looking for Values in Different Columns - VLOOKUP, MATCH, INDEX ???
    By juandyer in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-24-2015, 01:41 AM
  4. [SOLVED] index/match or vlookup question over multiple columns
    By lilsnoop in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 03-06-2015, 05:16 PM
  5. [SOLVED] VLOOKUP (or Index/Match) across four columns -- and returning multiple matches
    By rcasey in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-11-2013, 05:20 PM
  6. [SOLVED] vlookup or index-match for multiple columns
    By nmprodan in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-10-2013, 10:48 PM
  7. index/match function as vlookup for 2 columns
    By chmielko in forum Excel General
    Replies: 3
    Last Post: 05-04-2011, 07:30 PM

Tags for this Thread

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