简体   繁体   English

Excel公式在一系列数字变为负数时确定单元格ID

[英]Excel formula to determine cell ID when a series of numbers turns negative

Sample data样本数据

     A            B
1  Date        Amount
2  Apr 1        $6,000
3  May 1        $4,250
4  June 1       $2,750
5  July 1       $1,000
6  Aug 1       -$0.075   <- This Cell/Row
7  Sept 1     -$0.2500

In a column of numbers (in reality 100-200 rows), when the value changes to negative, eg if these we're amounts owed on a loan, when the loan would be paid off by.在一列数字(实际上是 100-200 行)中,当值变为负数时,例如,如果这些是我们欠贷款的金额,那么贷款将在何时还清。 Note the real difference between the numbers fluctuates based on interest, taxes, one-off payments etc. So I can't just count (total / payment) = number of months.请注意,数字之间的实际差异会根据利息、税收、一次性付款等而波动。所以我不能只计算(总额/付款)= 月数。

Is there a way to use Excel's formulas to determine this?有没有办法使用 Excel 的公式来确定这一点? This may be a case of requiring VBA (which is fine) but if I can avoid it, I'd like to.这可能是需要 VBA 的情况(这很好),但如果我能避免它,我想。

The match function returns a range index匹配 function 返回范围索引

=MATCH(matchValue, range, matchType: 0=exact, 1=greater than, -1=less than


=MATCH(0, B2:B7, -1)

Match the first cell that is less than 0 in range B2:B7.匹配范围 B2:B7 中小于 0 的第一个单元格。 From your sample data this would return 5从您的示例数据中,这将返回 5

Use the Offset function to return a particular cell based on the index value使用偏移量 function 根据索引值返回特定单元格

Use the MATCH formula to determine the row number.使用MATCH公式确定行号。

=MATCH(lookup value, lookup range, lookup type)
=MATCH(0,B1:B7,-1)

You will need to use match type of -1, as your data is in descending order.您将需要使用匹配类型 -1,因为您的数据是按降序排列的。 This setting will return the smallest value that is greater than or equal to the lookup value of 0.此设置将返回大于或等于查找值 0 的最小值。

Based on your data, this would return the row number 5 .根据您的数据,这将返回行号5 You are expecting to see the row number 6 , so the formula needs to be extended as follows.您期望看到行号6 ,因此需要将公式扩展如下。

=MATCH(0,B1:B7,-1)+1

To determine the cell ID you would need to wrap this formula into an ADDRESS formula.要确定单元格 ID,您需要将此公式包装到ADDRESS公式中。

=ADDRESS(Row number, Column number)
=ADDRESS(MATCH(0,B1:B7,-1)+1,2)

This would return the value $B$6这将返回值$B$6

It would probably be more useful to return the related date or value.返回相关的日期或值可能会更有用。 This can be done with an OFFSET formula.这可以通过OFFSET公式来完成。

=OFFSET(A1,MATCH(0,B1:B7,-1),0)
=OFFSET(A1,MATCH(0,B1:B7,-1),1)

The first formula would return the date in A6, Aug 1第一个公式将返回 A6 中的日期, 8 月 1 日

The second formula would return the value in B6, -$0.075第二个公式将返回 B6 中的值-$0.075

I'm not sure want you want to do.我不确定你想要做什么。

If you want to avoid having negative number you can do:如果你想避免有负数,你可以这样做:

=IF(YOUR_CELL_ACTUAL_FORMULA < 0 , 0, YOUR_CELL_ACTUAL_FORMULA)

If you want to know when the number turn to be negative you can do:如果您想知道数字何时变为负数,您可以执行以下操作:

=MATCH(0, YOUR_AMOUNT_RANGE, -1)

This will give you the first line number when the amount is negative.当金额为负数时,这将为您提供第一行号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM