[英]Get the column number of the last non-empty cell within a range (if values are not unique)
I have the following Excel-Spreadsheet: 我有以下Excel电子表格:
A B C D E F G H I J
1
2
3
4 200 150 80 300 4
5 200 150 80 150 2
6
7
In Range J4:J5
I have the following formulas: 在范围
J4:J5
我有以下公式:
J4 = MATCH(LOOKUP(2,1/(D4:I4<>0),D4:I4),D4:I4,0)
J5 = MATCH(LOOKUP(2,1/(D4:I4<>0),D4:I4),D4:I4,0)
With this formula I want to identify the last non-empty cell within the range and get the the column number of it back. 使用此公式,我想确定范围内的最后一个非空单元格,并获取其列号。 All this works perfectly in
Cell J4
. 所有这些都可以在
Cell J4
完美地工作。
However, in Cell J5
I get back number 2 instead of number 4 . 但是,在
Cell J5
我返回了数字2而不是数字4 。 As far as I can see the reason for this is that in Range D5:I5 the values are not unique (150 appears two times). 据我所知,这是因为范围D5:I5中的值不是唯一的(150次出现两次)。
What do I need to change in my formula to always get the column number of the last non-empty cell no matter if the values are unique or not? 无论值是否唯一,我都需要更改公式以始终获取最后一个非空单元格的列号吗?
The answer from this question does not help because my range is not starting in Column A
. 这个问题的答案无济于事,因为我的范围不是从
Column A
开始。
The range can be anywhere on the sheet. 该范围可以在图纸上的任何位置。
You only need MATCH: 您只需要匹配:
=MATCH(1E+99,D4:I4)
if you are looking for text then: 如果您正在寻找文字,则:
=MATCH("zzz",D4:I4)
Or either: 或者:
=MAX(IFERROR(MATCH(1E+99,D4:I4),0),IFERROR(MATCH("zzz",D4:I4),0))
The issue is that the LOOKUP returns the actual value, in the case of the error it returns 150 to the MATCH: 问题在于,LOOKUP返回实际值,如果发生错误,则它向MATCH返回150:
MATCH(150,D4:I4,0)
Which will return the first match location. 它将返回第一个比赛位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.