问题
I have 2 workbooks.
First is called June2122.xls
It has columns such as Last Name
(B2:B300), First Name
(C2:B300), etc...
Second is June Emails.xls
It has columns such as Last Name
(B2:B300), First Name
(C2:C300), Email Address
(D2:D300). These three columns are in a name range called Data_Table
What I need to do is compare the First Name
and Last Name
(B2:C2) from June2122.xls
with the First Name
and Last Name
(B2:C2) from June Emails.xls
. If they match then I need to populate the email address from June Emails.xls
(D2) into a new cell on June2122.xls
All cells are formated as "General".
I've tried several formulas, the closest I've got was this one:
=IF(ISNA(VLOOKUP(B2,'June Emails.xls'!Data_Table,2,TRUE)),0,VLOOKUP(C2,'June Emails.xls'!Data_Table,3,TRUE))
and all I get is a "FALSE" in the cell the email should be populating in.
Can anyone help with this? Thanks very much in advance!
回答1:
Hi I know this is an old topic but I have just found Stack overflow,
The following formula will do a lookup based on concatenated Values without a need for an additional concatenated field to be added
=IFERROR(INDEX(Sheet1!C$2:C$7,MATCH((A2&B2),(Sheet1!A$2:A$7&Sheet1!B$2:B$7),0),0),0)
**NB: This is an Array Formula so remember to use Ctrl-Shift-Enter to get it to work :)
so you can see what each part is referencing (sorry I used my own dummy data) here are the two data tables
The Formula above is used in cell C2 of Sheet2 and is looking up the values of Sheet2!A2 & B2 against Sheet1 column A and B
Figuring out this formula has saved me days of work, I hope it helps :)
回答2:
I figured it out. For demonstrational purposes, I'll use to test workbooks.
test1.xlsx
, workbook with first name, last name, phone number, and no email address
test2.xlsx
, workbook with first name, last name, and email address
So I need to populate the email addresses for each record from test2.xlsx
into test1.xlsx
by checking if the names match using VLOOKUP.
Step 1.) I have to combine the first_name
and last_name
fields and store the values in one cell.
To do this:
a. Create a new column in each workbook. I named it full_name
b. In the new column in each workbook, create the forumla
=(A2&B2)
. This will join the two values together. Like so:
c. Then select all the fields in that new
full_name
column and copy then paste special > values (to get rid of the formula)
Step 2.) Now that we have our new columns with the data we need to lookup in each workbook, we're going to create a new range in the workbook containing the email address (
test2.xlsx
). So highlight the two columns full_name
and email_address
and define a name.
Step 3.) Now return to your
test1.xlsx
workbook (the one that does not have the email addresses populated) and in the empty email_address
cell (we'll start with E2), write the following formula in the formula bar:
=VLOOKUP(D2,test2.xlsx!emailinfo,2,FALSE)
Keeping in mind that the syntax for the VLOOKUP function is:
= VLOOKUP ( lookup_value , table_array , col_index_num , range_lookup )
Step 4.) Now let's say someone didn't have an email address, say Tom Jones. We're going to get a nasty looking
#N/A
value in our cell:
To get rid of this:
a. Select all the column headers by clicking the 1
b. Click Data > Filter icon. Uncheck
(Select All)
and check ONLY #N/A
.
c. Click OK. Back to the work book, simply highlight the email field containing the value
#N/A
and delete.
Before:
After:
d. Either turn off your filter, or go back into filter settings and recheck
(Select All)
and now instead of nasty looking #N/A
s all over the place you'll have clean looking empty spaces.
(Obviously with small tables like this, the above seems a little impractical, but the ACTUAL workbooks I'm working with contains thousands of records so these tricks came quite in handy)
Hope this helps others in the future! Please leave any comments or alternatives or suggestions, feedback is always appreciated! :)
回答3:
without seeing the data, my best quess is you want "FALSE" as the last criteria in the VLookup, not "true" as you want an exact match.
http://office.microsoft.com/en-us/excel-help/vlookup-HP005209335.aspx
Also: could you use the trace formula evaluation to tell us exactly what part of forumla is resulting in the "FALSE" answer.
来源:https://stackoverflow.com/questions/11726245/vlookup-across-several-columns-in-two-workbooks