我在 Excel 电子表格中有一些数据结构如下:
A B C D E F
1 1 1 2 x 2 3
2 1 1 1 2 2 3
3 3 3 3 3 4 4
我正在尝试制定一个 Excel 公式,该公式将为我提供此表中最右列的索引,该表中有一个与特定值匹配的单元格。
在此示例中,包含值“1”的最右边的列位于 C 列中。对于“2”,它将是 E。该列索引就是我所追求的。
我使用列字母是为了与 Excel 一致,但最好使用数字列索引。
我已经尝试了一些其他解决方案来解决在线发现的类似 Excel 问题,但它们的行为并不完全正确。
I have some data structured like this in an Excel spreadsheet:
A B C D E F
1 1 1 2 x 2 3
2 1 1 1 2 2 3
3 3 3 3 3 4 4
I am trying to formulate an Excel formula which will give me the index of the rightmost column in this table which has a cell matching a specific value.
In this example, the rightmost column containing the value '1' is in column C. For '2' it would be E. That column index is what I'm after.
I use column letters to be Excel-consistent, but a numeric column index is preferable.
I have tried some other solutions for similar Excel problems found online, but they don't quite have the right behavior.
发布评论
评论(4)
如果你想使用辅助列,你可以把这个公式放在 G1 中
输入的数组中。向下填充至G3。在 G4 中,输入
然后对每个数字重复。如果您不需要辅助列,您可以编写一个像这样的 UDF,
您可以这样调用
If you want to use helper columns, you can put this formula in G1
That's array entered. Fill down to G3. In G4, put
Then repeat for each number. If you don't want helper columns, you can write a UDF like this
Which you call like
这是一种用公式来实现的方法。我将展示如何使用几个不同的公式来展示逻辑步骤,然后将它们组合成一个大公式。
首先,每列使用一个公式来查看目标值是否在该列中。例如,在 A 列中:
然后,将 IF 语句添加到这些公式中,将其转换为列号。如果列中存在查询,则显示列号,否则显示零。
最后,添加一个公式以从先前的公式中获取最大列数。这将等于最右边包含您的查询值的列。
Here is a way to do it with formulas. I'll show how to do it with a few different formulas to show the steps of the logic, and then put them together into one big formula.
First, use one formula per column to see if the target value is in the column. For example in column A:
Then, add IF statements to these formulas to translate this into column numbers. If the query is present in the column, show the column number, else show zero.
Finally, add a formula to grab the maximum column number from the prior formulas. This will equal the rightmost column with your query value in it.
怎么样:
How about:
这是使用新的
LAMBDA
和BYROW
函数的解决方案。BYROW
查看设定范围内的每一行,并返回目标编号所在的最右侧的列索引号。IFERROR
用于捕获目标编号不存在的任何错误,MAX
用于返回最大编号/最右侧索引列。完整教程在这里
Here's a solution using the new
LAMBDA
andBYROW
functions.The
BYROW
looks at each line in a set range and returns the right-most column index number where the goal number is present. TheIFERROR
is used to catch any errors where the goal number isn't present, and theMAX
is used to return the highest number/rightmost indexed column.Full Tutorial Here