我在Excel中有这样的数据:
A
1|id
2|2
3|4
4|8
5|12
6|16
7|20
8|24
9|28
10|32
11|36
12|40
我想根据以下条件在另一列中填充值:
if cell A2>0 && cell A2<=8
return 1
else if cell A2>8 && cell A2<=16
return 2
else if cell A2>16 && cell A2<=24
return 3
else if cell A2>24 && cell A2<=32
return 4
else return 5
我只能在一种IF
情况下做到这一点:
=IF(AND(A2>0,A2<8),1)
如何添加逻辑else if
?
就像我在上面的评论中说的那样,您不需要vba。
该IF
语法如下
=If(Condition, Do If True, Do If False)
所以在你的情况下
Condition = AND(A2>0,A2<8)
Do If True = 1
Do If False = Nothing?
Do If False
设置下一个条件的地方也是如此。例如
=If(Condition, Do If True, If(Condition, Do If True, Do If False))
等等...
这样的事情我以第二个条件(> 8,<16)为例。进行相应的更改。
=IF(AND(A2>0,A2<8),1,IF(AND(A2>8,A2<16),2,Next condition goes here))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句