我正在使用 excel 并且有两列(A 和 B)的值
我想搜索 A 列中的每个值并返回 B 列中的位置。
我正在使用这个公式:
IFERROR(MATCH("Values in Column A";"Array = Column B";0);0)
结果是:
Column A | Column B | Column C
1 | 4 | 2
2 | 1 | 3
3 | 2 | 4
4 | 1 | 1
1 | 2 | 2
| 3 |
如果它没有遇到重复的值,它就可以正常工作。但是,我希望它遇到重复的值,因此公式应该忽略之前遇到的值并遍历其他值。所以正确的结果应该是这样的:
Column C
2
3
5
1
4
你能帮我解决这个问题吗?有为此的VBA例程吗?
最佳答案
来自文章Getting the 2nd matching value from a list using VLOOKUP formula ,您可以创建一个辅助列来附加每个值的实例编号,以创建唯一的 id。
例如,在 C 列中,添加以下函数:
=A1&"-"&COUNTIF($A$1:A1,A1)
Note: The relative reference on the count range will cause the applicable range to grow as it is dragged down. The count of the items matching that cell in a range containing only that cell should always be one. As it gets dragged down to include other cells, it will increment accordingly.
然后在 D 列中添加相同的内容以获取 B 列中的单元格实例:
=B1&"-"&COUNTIF($B$1:B1,B1)
最后,像这样在 E 列中做你想做的数学:
=IFERROR(MATCH(C1,D:D,0),0)
关于用于比较具有重复值的列的 Excel 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31460390/