0

假设我有两个电子表格。

其中一个电子表格有如下表格:

  **Sheet 1**
  A        B        C        D
1 Name     Age      Rank     Number

2 George   22       Master   12

3 Paul     21       Acolyte  22

4 Jimmy    32       Horse    33
 
5 Agnor    12       Cheetah  90

另一个电子表格如下所示:

  **Sheet 2**
  A        B        C        D
1 Name     Age      Rank     Number

2 George   

3 Paul     21                22

4 Agnor    

我想将 Ages 从表 1 复制到表 2。所以我会复制 George、Paul 和 Agnor 的年龄,而忽略 Jimmy。我应该使用哪个函数来根据现有值复制数据?

有没有类似的东西:

foreach VAL in Sheet1
if(Sheet1.Name.EqualsIgnoreCase(Sheet2.Name))
{
    Sheet2.Age = Sheet1.Age;
}

我查了一下,很多人都说要使用 VLookup,但我不知道这将如何应用。

编辑

我在这里找到了一个类似的已解决问题(不知道我是怎么错过的):Compare and copy data between worksheets

但是,我对如何实现这一点仍然有些犹豫(我使用的是 Excel 2007)。

4

1 回答 1

1

vlookup would be the easiest way to go.
I will use cell B2 in sheet2 as the reference to try to explain the function
=VLOOKUP(A2,Sheet1!$A$2:$D$5,2,FALSE)
The first parameter is the data you are using for a lookup - you may want to change that to $A2 if you copy the formula around the sheet
The second parameter is where the data is that excel needs to find the value you referenced in the first parameter - use dollar signs. The data doesn't tend to move
The third parameter tells excel what info to return - the 2 means give me the 2nd piece of data
The last parameter tells excel if it can use a close match (FALSE for an exact match)

Now to follow Excel and see what it returns.....

First, it looks for George in the data (it knows it has to be an exact match from the fourth parameter)
Next, it finds the row George -- 22 -- Master -- 12 and gives the function the second value (22 in this case)

于 2012-05-29T19:32:53.023 回答