Is there such thing as a VLOOKUP that recognises repeated numbers?

时间:2016-10-15 16:58:47

标签: excel excel-formula excel-2010 offset vlookup

I have a list of values in column A on an excel TAB and on the column B next to it I have a list of words. On another TAB, I'm trying to retrieve the words from B where A has the smallest value, then the 2nd smaller value, 3rd, etc.

Example: Column A would have (2,3,3,6,8) and B (car,dog,cat,house,boat)

I firstly created a column where I retrieved the smallest values:

  • On column X1 I added: SMALL('Table'!$A:$A,1)
  • On column X2 I added: SMALL('Table'!$A:$A,2)
  • etc...

and then a VLOOKUP worked for me:

  • On column Y1 I added: VLOOKUP(X1,'Table'!$A:$B,2,FALSE)
  • On column Y2 I added: VLOOKUP(X2,'Table'!$A:$B,2,FALSE)

So far so good. My issue is when my values repeat. *i.e.: In the example above, whenever the function finds the value 3 in column A, I get the word dog twice instead of dog and cat because it just displays the first value the vlookup finds.

I've tried adding an offset: =OFFSET(SMALL('Table'!$A:$A,1),1,0) but not sure if it works to fetch from other TABS.

Any help or workaround for this please? Many thanks in advance.

1 个答案:

答案 0 :(得分:1)

我建议使用索引/匹配而不是VLOOKUP,如果之前发生过相同的值,则在匹配位置添加一个,如果在之前发生过两次,则添加两个等等: -

=INDEX(Table!B:B,MATCH(A2,Table!A:A,0)+COUNTIF(A$1:A1,A2))

你也可以使用这样的东西来获得最小的,第二小的等等而不是硬编码: -

=SMALL(Table!$A:$A,ROW(1:1))

enter image description here

确定我将用于分隔具有相等值的行的技巧是向每行添加少量以使值唯一。这是我的公式: -

=LARGE(IF(A$2:A$9="Restaurants",C$2:C$9),ROW(1:1))

获得最大值,这是一个标准公式

=INDEX(D$2:D$9,MATCH(LARGE(IF(A$2:A$9="Restaurants",C$2:C$9+ROW(C$2:C$9)/10^7),ROW(1:1)),C$2:C$9+ROW(C$2:C$9)/10^7,0))

获得匹配的城市。即使相邻行中的相等值不相同,这也会起作用。

我不知道您的实际数据中有多少行,如果超过100,您需要使用的数量少于.01。

请注意,这些是数组公式,需要输入 Ctrl Shift Enter

对于最小的,只需将LARGE更改为SMALL。

enter image description here

如果您想排除任何非数字值,例如"未排名"你需要

=INDEX(D$2:D$9,MATCH(LARGE(IF((A$2:A$9="Restaurants")*ISNUMBER(C$2:C$9),C$2:C$9+ROW(C$2:C$9)/10^7),ROW(1:1)),C$2:C$9+ROW(C$2:C$9)/10^7,0))

我不建议将其更改为使用D:D,C:C等因为它会很慢,但它会起作用。