简体   繁体   English

Excel:如何在一行中查找最后一个“有效”值

[英]Excel: How to find last “valid” value in a row

I have a workbook of the following style: 我有以下样式的工作簿:

| A    | B    | C    |
| 1    | y    |      |
| 2    | y    |      |
| 3    | n    |      |
| 4    | y    |      |
| 5    | n    |      |
| 6    | n    |      |
| 7    | y    |      |

In column CI want to have the last value from column A above the current row which has "y" in column B. 在CI列中,希望具有当前行上方 A列中的最后一个值,而B列中包含“ y”。

So, the expected output would be: 因此,预期输出为:

| A    | B    | C    |
| 1    | y    | ---  |
| 2    | y    | 1    |
| 3    | n    | 2    |
| 4    | y    | 2    |
| 5    | n    | 4    |
| 6    | n    | 4    |
| 7    | y    | 4    |

NB: I actually want to do this is Google Sheets, but I guess an ordinary Excel function would suffice. 注意:我实际上要使用Google Sheets,但是我想普通的Excel函数就足够了。

Thanks a lot! 非常感谢!

Your formula must check the "y" in the row previous, so in C2, you need to reference the string in B1, and either use the number in A1, or the previously selected value in column C. 您的公式必须在上一行中检查“ y”,因此在C2中,您需要引用B1中的字符串,并使用A1中的数字或C列中先前选择的值。

So the formula is: 因此公式为:

=if(B1="y",A1,C1)

Here's a screenshot of what it would look like: 这是它的屏幕截图: 在此处输入图片说明


Based on comment by OP, here is another screenshot showing exactly the output as requested in the question above: 根据OP的评论,这是另一个截屏,显示了上面问题中要求的输出:

在此处输入图片说明

Put the following formula into cell C2 , its an array formula so dont include the curly braces but press CTRL + SHIFT + ENTER to confirm the formula (instead of just ENTER ) 将以下公式放入单元格C2 ,将其作为数组公式,因此不包括花括号,而是按CTRL + SHIFT + ENTER确认公式(而不是ENTER

{=MAX(($B$1:$B1="y")*$A$1:$A1)}

You can drag that formula down. 您可以将该公式向下拖动。 I haven't tested this on Google Docs, but it works with excel. 我尚未在Google文档上对其进行过测试,但是它可以与excel一起使用。

请尝试,在C2中复制下来:

=IF(B1="y",MAX(A$1:A1),C1)

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

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