简体   繁体   English

根据 Excel 中的另一个单元格值验证单元格

[英]Validate cell based on another cell value in Excel

I have this table我有这张桌子

Counter    | String
---------------------
four       | Apple
six        | Banana

And want to validate the cells in the column String based on the value of the previous cell in the same row Counter Column.并希望根据同一行Counter Column 中前一个单元格的值来验证String列中的单元格。

What I did?我做了什么?

-> Data -> Data Validation -> Custom and here's the formula i've written -> 数据 -> 数据验证 -> 自定义,这是我写的公式

=AND(LEN(ADDRESS(ROW(),COLUMN()))=4, INDIRECT(ADDRESS(ROW(),COLUMN()-1)) = "four")

But it doesn't work with me, anyone can help me in that?但这对我不起作用,任何人都可以帮助我吗?

INDIRECT returns the cell reference rather than the cell value. INDIRECT返回单元格引用而不是单元格值。 Used in a cell this is not really a difference but used elsewhere there can be problems.在单元格中使用这并不是真正的区别,但在其他地方使用可能会出现问题。 In your case the cell reference is not equal "four" but the value behind that cell reference is.在您的情况下,单元格引用不等于“四”,但该单元格引用背后的值是。 To solve those problems you can wrap the INDIRECT in N or T dependent of whether the result is numeric or text.要解决这些问题,您可以将INDIRECT包装在NT中,具体取决于结果是数字还是文本。

So in your case:所以在你的情况下:

=AND(LEN(ADDRESS(ROW(),COLUMN()))=4,T(INDIRECT(ADDRESS(ROW(),COLUMN()-1)))="four")

This should work if applied to the column String .如果应用于列String ,这应该可以工作。

But massive using INDIRECT should be avoided because of it's volatile behavior.但是应该避免大量使用INDIRECT ,因为它的行为不稳定。 Most times it can be replaced using INDEX .大多数时候可以使用INDEX替换它。 So also in this case.在这种情况下也是如此。

=AND(ROW()<10,COLUMN()<27,INDEX($A$1:$Z$9,ROW(),COLUMN()-1)="four")

should be the same.应该是一样的。

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

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