IF both first and last name are in the cell, spit back ID

Joined
Apr 16, 2021
Messages
44
Office Version
  1. 365
Platform
  1. Windows
  2. Web
Hi,

I am trying to import ID numbers from spreadsheet2 into spreadsheet1. Spreadsheet2 contains both names and ID numbers, while spreasheet1 contains just names.

However, the names don't always appear identically on both lists. For example, a name might appear once with a middle initial and once without a middle initial.

Spreadsheet1:
1619550301045.png

Spreadsheet2:
1619550219012.png


To prevent it from giving an error when it doesn't match exactly, I tried to circumvent it by splitting the name column on spreadsheet2 into Last, First, and MIddle initial columns and then telling it that it needs to contain both the first and last name in order to return the ID. I wrote the following formula:

=IF(AND(ISNUMBER(SEARCH('Spreadsheet2'!L2,B2)),ISNUMBER(SEARCH('Spreadsheet2'!M2,B2))),INDEX('Spreadsheet2'!$A:$A,MATCH(B2,'Spreadsheet2'!$B:$B,0)),"Fill in")

What am I doing wrong?

Thank you!
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi,

I am trying to import ID numbers from spreadsheet2 into spreadsheet1. Spreadsheet2 contains both names and ID numbers, while spreasheet1 contains just names.

However, the names don't always appear identically on both lists. For example, a name might appear once with a middle initial and once without a middle initial.

Spreadsheet1:
View attachment 37617
Spreadsheet2:
View attachment 37616

To prevent it from giving an error when it doesn't match exactly, I tried to circumvent it by splitting the name column on spreadsheet2 into Last, First, and MIddle initial columns and then telling it that it needs to contain both the first and last name in order to return the ID. I wrote the following formula:

=IF(AND(ISNUMBER(SEARCH('Spreadsheet2'!L2,B2)),ISNUMBER(SEARCH('Spreadsheet2'!M2,B2))),INDEX('Spreadsheet2'!$A:$A,MATCH(B2,'Spreadsheet2'!$B:$B,0)),"Fill in")

What am I doing wrong?

Thank you!
The problem is:
Excel Formula:
MATCH(B2,'Spreadsheet2'!$B:$B,0)

You're trying to match Ben Robins in a list that doesn't contain that entry. B2 (Ben Robins) cannot be located in B:B (Robins, Ben).

Try:
Excel Formula:
=INDEX(Spreadsheet2!A:A,MATCH(RIGHT(Spreadsheet1!B2,LEN(B2)-FIND(" ",Spreadsheet1!B2))&", "&LEFT(Spreadsheet1!B2,FIND(" ",Spreadsheet1!B2)-1),Spreadsheet2!B:B,0),1)

That is assuming the name is always listed as "Last, First" without a middle initial.
 
Last edited:
Upvote 0
The problem is:
Excel Formula:
MATCH(B2,'Spreadsheet2'!$B:$B,0)

You're trying to match Ben Robins in a list that doesn't contain that entry. B2 (Ben Robins) cannot be located in B:B (Robins, Ben).

Try:
Excel Formula:
=INDEX(Spreadsheet2!A:A,MATCH(RIGHT(Spreadsheet1!B2,LEN(B2)-FIND(" ",Spreadsheet1!B2))&", "&LEFT(Spreadsheet1!B2,FIND(" ",Spreadsheet1!B2)-1),Spreadsheet2!B:B,0),1)

That is assuming the name is always listed as "Last, First" without a middle initial.
Hmm... I get what you're saying.

How would I do it, then?

I am trying to tell it that if a cell contains both Ben and Robins, then it should return the ID that matches with that cell.
 
Upvote 0
Hmm... I get what you're saying.

How would I do it, then?

Spreadsheet1, cell A2:
Excel Formula:
=IFERROR(INDEX(Spreadsheet2!A:A,MATCH(RIGHT(Spreadsheet1!B2,LEN(B2)-FIND(" ",Spreadsheet1!B2))&", "&LEFT(Spreadsheet1!B2,FIND(" ",Spreadsheet1!B2)-1),Spreadsheet2!B:B,0),1),"Fill in")

You don't need that secondary lookup set in columns L:N on Spreadsheet2.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,819
Messages
6,121,727
Members
449,049
Latest member
MiguekHeka

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