简体   繁体   中英

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.

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. 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.

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 .

But massive using INDIRECT should be avoided because of it's volatile behavior. Most times it can be replaced using INDEX . So also in this case.

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

should be the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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