问题
I have 2 sheets with different values. I need to find a value from one cell.sheet1 in sheet2 and copy value from nextcell_in_the_same_row.sheet1 to nextcell_in_the_same_row.sheet2. It is very difficult to explain let look at the example bellow.
E.g. Before
first sheet:
A B
1 aaa 123
2 bbb 456
3 ccc 789
4 ddd 122
second sheet:
A B
1 aaa
2 ada
3 cca
4 ccc
After
first sheet:
A B
1 aaa 123
2 bbb 456
3 ccc 789
4 ddd 122
second sheet:
A B
1 aaa *need to find value in the first sheet and copy value from B2 because aaa in A1*
2 ada *value does not exist in the first sheet so copy nothing*
3 cca *not need to copy because no value in the first sheet*
4 ccc *need to copy the value from B3*
Thank you so much!
回答1:
Use a VLOOKUP
along with an IFERROR
.
=IFERROR(VLOOKUP(A1, Sheet1!A:B, 2, 0), "")
This will do what you described (well described, by the way!) in your question. Drag the formula down in Sheet2
till the bottom.
VLOOKUP
takes the value of A1
in sheet 2 (no sheet reference because the value is in the same sheet as the formula) and looks it up in column A of Sheet1
.
It returns the second value (hence why 2
) of the table selected in the formula (column A is 1, column B is 2).
The 0 tells the VLOOKUP
to look for exact matches. You don't need approximate match here.
And IFFERROR
is there in case VLOOKUP
doesn't find anything (like with ada
) and instead of giving #N/A
, returns an empty cell, ""
.
来源:https://stackoverflow.com/questions/18164489/find-value-from-one-cell-copy-value-from-cell-near-to-that-cell-and-paste-it-to