Excel,如果函数,ifs,

时间:2017-01-11 03:50:52

标签: excel excel-vba if-statement excel-formula ifs vba

I assume x is the number I'm going to analyze and "y" is as "male" or "female" and "z" is as age group.

x是一个数字,结果将是“体重不足”,健康“或超重”。但对于男性和女性来说,实际上是BPI的x并不相同。例如,如果x = 21则取决于性别和年龄,它将被归类为“低于”,“健康”或超重“。

 Function BAI(x As Integer, y As String, z As Integer) As String


 If x < 21 And y = "female" And 20 <= z <= 39 Then
    BAI = "UNDERWEIGHT"

 Elseif 22 <= x <= 33 And y = "Female" And 20 <= z <= 39 Then
    BAI = "Healthy"

ElseIf 34 <= x <= 38 And y = "Female" And 20 <= z <= 39 Then
    BAI = "overweight"

ElseIf x >= 39 And y = "Female" And 20 <= z <= 39 Then
    BAI = "OBESE"

ElseIf x <= 23 And y = "female" And 40 <= z <= 59 Then
    BAI = "UNDERWEIGHT"

ElseIf 24 <= x <= 35 And y = "female" And 40 <= z <= 59 Then
    BAI = "Healthy"

ElseIf 36 <= x <= 41 And y = "female" And 40 <= z <= 59 Then
    BAI = "Overweight"

ElseIf x >= 42 And y = "female" And 40 <= z <= 59 Then
    BAI = "OBESE"

ElseIf x <= 25 And y = "female" And 60 <= z <= 79 Then
    BAI = "UNDERWEIGHT"

ElseIf 26 <= x <= 38 And y = "female" And 60 <= z <= 79 Then
    BAI = "Healthy"

ElseIf 39 <= x <= 43 And y = "female" And 60 <= z <= 79 Then
    BAI = "Overweight"

ElseIf x >= 44 And y = "female" And 60 <= z <= 79 Then
    BAI = "obese"

ElseIf x <= 8 And y = "male" And 20 <= z <= 39 Then
    BAI = "Underweight"

ElseIf 9 <= x <= 21 And y = "male" And 20 <= z <= 39 Then
    BAI = "Healthy"

ElseIf 22 <= x <= 26 And y = "male" And 20 <= z <= 39 Then
    BAI = "overweight"

ElseIf x >= 27 And y = "male" And 20 <= z <= 39 Then
    BAI = "OBESE"

ElseIf x <= 11 And y = "male" And 40 <= z <= 59 Then
    BAI = "UNDERWEIGHT"

ElseIf 12 <= x <= 23 And y = "male" And 40 <= z <= 59 Then
    BAI = "Healthy"

ElseIf 24 <= x <= 28 And y = "male" And 40 <= z <= 59 Then
    BAI = "Overweight"

ElseIf x >= 29 And y = "male" And 40 <= z <= 59 Then
    BAI = "OBESE"

ElseIf x <= 13 And y = "male" And 60 <= z <= 79 Then
    BAI = "UNDERWEIGHT"

ElseIf 14 <= x <= 25 And y = "male" And 60 <= z <= 79 Then
    BAI = "Healthy"

ElseIf 26 <= x <= 30 And y = "male" And 60 <= z <= 79 Then
    BAI = "Overweight"

 End If

 End Function

1 个答案:

答案 0 :(得分:0)

您可以使用IF工作簿功能获得所需的结果。要在单个IF条件中获得多个条件,请使用AND()和OR()函数。要创建if - elseif类型逻辑,请在相应的部分中添加IF()函数。作为一个例子

=IF(OR(AND(A1="Male", A2>20),AND(A1="Female",A2>30)), IF(A3>200,"overweight","healthy"),"otherstuff")

这应该让你开始走正确的道路。