简体   繁体   English

查找特定单元格上方的第一个特定值

[英]Finding the first specific value above a certain cell

I'm looking for a way to find the first specific value above a certain cell. 我正在寻找一种方法来找到特定细胞上方的第一个特定值。 Using the example below, in the result column every time I hit a A in COL2, I need to substract the value in COL1 to the first A value above. 使用下面的例子,每次我在COL2中点击A时,在结果列中,我需要将COL1中的值减去上面的第一个A值。

The trouble seems finding a way to keep the range dynamic... I thought of =IF(B5="A";A5-INDIRECT("A"&MATCH("A";B:B;0));"") 问题似乎找到一种方法来保持范围动态...我想到=IF(B5="A";A5-INDIRECT("A"&MATCH("A";B:B;0));"")

But of course that only works for the first one as Match will always pick up the first one. 但是当然这只适用于第一个,因为匹配将总是拿起第一个。

Any ideas? 有任何想法吗? Thanks! 谢谢!

Example : 示例:

COL1    COL2    Result
1       A   
2       0
3       0
4       A       4 - 1 = 3
5       0
6       A       6 - 4 = 2
7       0
8       0
9       0
10      A       10 - 6 = 4

Try this: 尝试这个:

=IF(AND(ROW(B2)<>2,B2="A"),A2-INDEX($A$1:$A1,AGGREGATE(14,6,ROW($1:1)/($B$1:$B1="A"),1)),"")

![在此处输入图像说明

The AGGREGATE() Function was introduced in 2010. AGGREGATE()函数于2010年推出。

  • In D2 enter =IF(B2="A",A2-INDIRECT("A"&MATCH("A"&(E2-1),F:F,0)),"") 在D2中输入=IF(B2="A",A2-INDIRECT("A"&MATCH("A"&(E2-1),F:F,0)),"")
  • In E2 enter =IF(B2="a",COUNTIFS($B$2:B2,"a"),"") 在E2中输入=IF(B2="a",COUNTIFS($B$2:B2,"a"),"")
  • In F2 enter =B2&E2 在F2中输入=B2&E2
  • Copy formulas from D, E and F down all your rows 从D,E和F复制所有行的公式

Column D is the result you're looking for D列是您正在寻找的结果

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

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