Excel: if cell 1 contains X or Y or Z, then cell 2

2020-03-07 06:48发布

As from the title, I need Excel to auto-populate the B row cells based on the corresponding A row cells content.

So if cell A1 contains X or Y or Z, then cell B1 should equal W, or if A1 contains G or H or J, cell B1 should equal W.

2条回答
混吃等死
2楼-- · 2020-03-07 07:27

You can try adding this formula to B1:

=IF(OR(A1="X";A1="Y";A1="Z");"W";IF(OR(A1="G";A1="H";A1="J");"W";""))

The first part checks if A1 is either X Y or Z. If it's true, it returns "W", if it's false, it will call for another IF statement, that checks if A1 is in G H or J. If it's true, yes, "W" again, if it's not, it'll just put nothing in there.

It's possible to simplify it, by using only one IF/OR like this:

=IF(OR(A1="X";A1="Y";A1="Z";A1="G";A1="H";A1="J");"W";"")

You might have to replace ; with , depending on your locale settings.

查看更多
你好瞎i
3楼-- · 2020-03-07 07:48

If the comparative values are to be hard-coded into the formula, it can be tightened up like this.

=IF(OR(A1={"X","Y","Z"}), "W", IF(OR(A1={"G","H","I"}), "K", ""))
查看更多
登录 后发表回答