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

Lil2606

Board Regular
Joined
Jan 29, 2019
Messages
79
Hi all,

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.

This question is posted on ExcelForum as well link: https://www.excelforum.com/excel-pr...value-vba-loops-with-example.html#post5070771

I have posted an example workbook there as well.

So,
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)

Sheet1 DataTable Names and countries are also surrounded by other data, so I can't just copy over the AidTable and remove duplicates.

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?
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,624
Latest member
gregg777

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top