/ / Excel, wenn Funktion, ifs, - Excel, Excel-VBA, If-Anweisung, Excel-Formel, Ifs, Vba

Excel, wenn Funktion, ifs, - Excel, Excel-VBA, If-Anweisung, Excel-Formel, 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 ist eine Zahl, die das Ergebnis sein wird"Untergewicht", "gesund" oder "übergewichtig". aber x, was eigentlich der BPI ist, ist für Männer und Frauen nicht dasselbe. Wenn z. B. x = 21, dann abhängig von Geschlecht und Alter, würde es als "untergewichtig", "gesund" oder "übergewichtig" kategorisiert werden.

 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

Antworten:

0 für die Antwort № 1

Sie können Ihr gewünschtes Ergebnis mit dem IF erhaltenArbeitsmappenfunktion. Um mehrere Kriterien in einer einzigen IF-Bedingung zu erhalten, verwenden Sie die Funktionen AND () und OR (). Um if - elseif type logic zu erstellen, fügen Sie IF () -Funktionen innerhalb der entsprechenden Abschnitte hinzu. als Beispiel

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

Dies sollte Sie auf den richtigen Weg bringen.