/ / Excel、if、if、excel、excel-vba、if-statement、excel-formula、ifs、vba

エクセル、if-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

IFを使用して目的の結果を得ることができますブック機能。 1つのIF条件で複数の基準を取得するには、AND()およびOR()関数を使用します。 if - elseif型ロジックを作成するには、適切なセクションの中にIF()関数をネストします。例として

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

これはあなたが正しい道を歩み始めるはずです。