在另一个表中查找值,返回行索引

发布于 2024-11-26 00:01:28 字数 1788 浏览 2 评论 0原文

我对 Excel 函数缺乏经验,在以下情况下需要一些帮助:

表 I 有 2 列:

X      Y 
3.2   result
4.7   result
1.2   result

表 II 有这些列:

A    B    C    D
1   1.2  0.0  2.3
2   4.1  3.2  0.0
3   0.0  4.7  0.0

我将尝试说明我想用 C++/C#/Java 编程语法做什么:

在 Y[ 1] 我想存储:

foreach (int value in TableII)   //look for X[1] in Table 2
   if( value == X[1] ){          //when you find it, 
      return A[value.rowNumber]; //return the corresponding value from A
      //break;
   }

换句话说,我想在表II中找到X[1](它总是在那里,并且总是只有一次),并从A[与表II具有相同索引的列中返回相应的值匹配]。

我已经研究过 HLOOKUP 但它不仅仅是一个命令。请帮忙。


[编辑]

我已经尝试过这个=INDEX(Column1,IFERROR(MATCH(I2,Column2,0),IFERROR(MATCH(I2,Column3,0),IFERROR(MATCH(I2,Column4,0),IFERROR(MATCH(I2,Col) umn5,0),IFERROR(MATCH(I2,Column6,0),IFERROR(MATCH(I2,Column7,0),IFERROR(MATCH(I2,Column8,0),MATCH(I2,Column9,0))))) ))))

但我收到“嵌套级别超过当前文件格式允许的级别”错误。如果我只删除一个 IFERROR(MATCH(I2,Column8,0),那么它就可以工作。但是我需要第 2 到 9 列,其中 Column1 保存索引。

我认为 Excel 2007 和 2010 没有 (对于刚接触 Excel 的人来说,“Column1”等是通过选择列、

右键单击所选内容并“定义名称”来创建的。)


[EDIT2]

所以我通过将公式分成两部分来“解决”我的嵌套问题,使用 + ,让 ifs 返回 0,以防两边都没有匹配,这样你要么有 <。 code>something + 0 或 0 + some,所以它有效,

这是我现在使用的公式:

    =INDEX(Column1, IFERROR(MATCH(I3,Column2,0),IFERROR(MATCH(I3,Column3,0),IFERROR(MATCH(I3,Column4,0),IFERROR(MATCH(I3,Column5,0),IFERROR(MATCH(I3,Column6,0),IFERROR(MATCH(I3,Column7,0),0))))))    
                    +     
                    IFERROR(MATCH(I3,Column8,0),IFERROR(MATCH(I3,Column9,0),0))
          )

我已经接受了 Chris 的回答,因为他做了大部分工作。 ,但我还是想知道如果我的解决方法是好的做法,并且没有更短/更好的方法来做到这一点,

谢谢。

I'm inexperienced in Excel functions and need some help with the following scenario:

Table I has 2 columns:

X      Y 
3.2   result
4.7   result
1.2   result

Table II has these columns:

A    B    C    D
1   1.2  0.0  2.3
2   4.1  3.2  0.0
3   0.0  4.7  0.0

I will try to illustrate what I want to do in C++/C#/Java programming syntax:

In Y[1] I want to store:

foreach (int value in TableII)   //look for X[1] in Table 2
   if( value == X[1] ){          //when you find it, 
      return A[value.rowNumber]; //return the corresponding value from A
      //break;
   }

In other words, I want to find X[1] in table II (it will always be there, and always just once), and return the corresponding value from column A[of the same index as the match].

I've looked at HLOOKUP but there's more to it that just one command. Please help.


[EDIT]

I've tried this =INDEX(Column1,IFERROR(MATCH(I2,Column2,0),IFERROR(MATCH(I2,Column3,0),IFERROR(MATCH(I2,Column4,0),IFERROR(MATCH(I2,Column5,0),IFERROR(MATCH(I2,Column6,0),IFERROR(MATCH(I2,Column7,0),IFERROR(MATCH(I2,Column8,0),MATCH(I2,Column9,0)))))))))

But I get the "more levels of nesting than are allowed in the current file format" error. If I remove just one IFERROR(MATCH(I2,Column8,0), then it works. But I need Columns 2 to 9, with Column1 holding the index.

I thought Excel 2007 and 2010 do not have nesting limits any more. What gives?

(For anyone new to Excel reading this, "Column1" etc. are made by selecting the column, right clicking on the selection, and "Define Name".)


[EDIT2]

So I "solved" my nesting problem by dividing the formula into 2 parts, with a +, having the ifs return 0 in case there's no match in either side. This way you either have something + 0 or 0 + something, so it works.

Here's the formula I'm using right now:

    =INDEX(Column1, IFERROR(MATCH(I3,Column2,0),IFERROR(MATCH(I3,Column3,0),IFERROR(MATCH(I3,Column4,0),IFERROR(MATCH(I3,Column5,0),IFERROR(MATCH(I3,Column6,0),IFERROR(MATCH(I3,Column7,0),0))))))    
                    +     
                    IFERROR(MATCH(I3,Column8,0),IFERROR(MATCH(I3,Column9,0),0))
          )

I've accepted Chris' answer, as he did most of the work, but I would still like to know if my workaround is good practice and if there isn't a shorter/better way to do this.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绝情姑娘 2024-12-03 00:01:28

这是 Y 的可能公式(假设表 I 位于 G:H 列中)

=INDEX($A:$A,IFERROR(MATCH(G2,$B:$B,0),IFERROR(MATCH(G2,$C:$C,0),MATCH(G2,$D:$D,0))))

注意 IsError 函数是在 Ecel 2007 中引入的

如果您的表实际上定义为 excel 表,您可以使用

=INDEX(Table2[Column1],IFERROR(MATCH([@X],Table2[Column2],0),IFERROR(MATCH([@X],Table2[Column3],0),MATCH([@X],Table2[Column4],0))))

(替换您自己的表和列名称)

Here's a possible formula for Y (assumes table I is located in columns G:H)

=INDEX($A:$A,IFERROR(MATCH(G2,$B:$B,0),IFERROR(MATCH(G2,$C:$C,0),MATCH(G2,$D:$D,0))))

Note the IsError function was introduced in Ecel 2007

If your tables are actually defined as excel tables you can use

=INDEX(Table2[Column1],IFERROR(MATCH([@X],Table2[Column2],0),IFERROR(MATCH([@X],Table2[Column3],0),MATCH([@X],Table2[Column4],0))))

(substitute your own table and column names)

懒猫 2024-12-03 00:01:28

如果您的值是唯一的,则可以使用以下公式而无需执行任何嵌套:

=INDEX(column1,SUMPRODUCT((Table2=G24)*ROW(Table2)))

If your values are unique, you can use the following formula without having to do any nesting:

=INDEX(column1,SUMPRODUCT((Table2=G24)*ROW(Table2)))

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文