检索与行

时间:2016-06-23 00:24:24

标签: excel excel-vba excel-formula vba

我正在使用两个表,我正在尝试从列中第一行中提取数据,该列中的值与A2中的数据相匹配。

示例表...

ID#s  RESULT
9
17
49
43
5
32
46
56
20
36
37

test1   test2   test3   test4   test5   test6   test7
  1       9       17      25      33      41      49
  2       10      18      26      34      42      50
  3       11      19      27      35      43      51
  4       12      20      28      36      44      52
  5       13      21      29      37      45      53
  6       14      22      30      38      46      54
  7       15      23      31      39      47      55
  8       16      24      32      40      48      56

所以基本上,这是两个不同的表。查看第一个表,我希望公式进入B2并在A2中找到值(在本例中为数字9),然后在第二个表中找到它并返回列的第一行中的值9因此,B2应返回“test2”,因为它在“test2”列中找到了数字9。最终结果如下所示......

ID#s  RESULT
9      test2
17     test3
49     test7
43     test6
5      test1
32     test4
46     test6
56     test7
20     test3
36     test5
37     test5

我知道怎么回事吗?希望我已经彻底解释了我要求帮助的内容。

2 个答案:

答案 0 :(得分:2)

在点击ctrl+shift

时按住enter,尝试输入此公式
=OFFSET(Table2,0,MAX(IF(A2=Table2,COLUMN(Table2)))-COLUMN(Table2))

鉴于您的数据,我们返回:

enter image description here

如果您碰巧拥有Excel 2016,并且还希望使用带有结构化引用的表,则可以使用此公式(也使用CSE输入):

=TEXTJOIN(,,IF(A2=myDataTable,myDataTable[#Headers],""))

答案 1 :(得分:-2)

使用VLOOKUP方法可以实现这一点。此页面说明了如何使用它:http://www.gcflearnfree.org/excel-tips/how-to-use-excels-vlookup-function/1/

希望这有帮助。