Get the last column number of a search criteria in a defined range (if values are not unique)

谁都会走 提交于 2020-03-05 06:06:32

问题


I have the following Excel spreadsheet:

   A      B                  C          D       E       F      G        H        I  
1     Search Criteria:    Prod.B
2     Column:               2
3                                   Prod.A   Prod.B  Prod.B  Prod.C   Prod.C   Prod.D
4                      
5      

Currently I use the following formula in Cell C2 to get the column of the search criteria in Cell C1 in the Range D3:I3.

=MATCH(C1,D3:H3,0)

All this works perfectly.


However, as you can see with the formula above I get back the first column number in which the search criteria appears.

What do I need to change in the formular to get the last column number in which the search criteria appears? (In the example above it would be 3)


回答1:


=MAX(IF(D3:I3=C1,COLUMN(D3:I3)-3))

Or:

=MATCH(2,1/(D3:I3=C1))

Enter both as array through CtrlShiftEnter


Alternatively:

=LOOKUP(2,1/(D3:I3=C1),COLUMN(D3:I3)-3)

It should still be an array formula but you don't have to enter it as such.



来源:https://stackoverflow.com/questions/58114477/get-the-last-column-number-of-a-search-criteria-in-a-defined-range-if-values-ar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!