Formula to generate a value according to a range

99封情书 提交于 2019-12-02 23:18:52

问题


I want to populate a cell according to the range of another cell. Like if the independent cell has the value between 12 to 16 then the dependent cell will be populated as -2 and if the independent cell has a value between 16 to 20 then -1 and if 20-24 then N and so on:

Sample

Is there any formula or how otherwise can I do it?


回答1:


Assuming 16 is "between" 16-20 rather than "between" 12-16 and that for N it is the text of the OP that counts rather than the image:

=LOOKUP(A1,{12,16,20,24},{-2,-1,"N"})  

Negative values, zero, numbers less than 12 and positive or greater than 24, blanks and text would return #N/A.

LOOKUP.




回答2:


You could do it like this (place this formula in B1):

=IF(AND(A1>=12;A1<=15);"-2";IF(AND(A1>=16;A1<20);"-1";IF(AND(A1>=20;A1<25);"N";"N/A")))


来源:https://stackoverflow.com/questions/34238188/formula-to-generate-a-value-according-to-a-range

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!