(その他) 無効の値
::::::::::::::::::::::::::::::::::::::
回答例
Sub テスト評価①()
Dim 行 As Integer
Dim 上端 As Integer
Dim 下端 As Integer
上端 = 2
下端 = 7
For 行 = 上端 To 下端
If 0 <= Cells(行, 2) And Cells(行, 2) <= 59 Then
Cells(行, 3) = "不可"
ElseIf 60 <= Cells(行, 2) And Cells(行, 2) <= 69 Then
Cells(行, 3) = "可"
ElseIf 70 <= Cells(行, 2) And Cells(行, 2) <= 79 Then
Cells(行, 3) = "良"
ElseIf 80 <= Cells(行, 2) And Cells(行, 2) <= 89 Then
Cells(行, 3) = "優"
ElseIf 90 <= Cells(行, 2) And Cells(行, 2) <= 100 Then
Cells(行, 3) = "秀"
Else
Cells(行, 3) = "無効の値"
End If
Next 行
End Sub
Sub テスト評価②()
Dim 行 As Integer
Dim 上端 As Integer
Dim 下端 As Integer
上端 = 2
下端 = 7
For 行 = 上端 To 下端
Select Case Cells(行, 2)
Case 0 To 59
Cells(行, 3) = "不可"
Case 60 To 69
Cells(行, 3) = "可"
Case 70 To 79
Cells(行, 3) = "良"
Case 80 To 89
Cells(行, 3) = "優"
Case 90 To 100
Cells(行, 3) = "秀"
Case Else
Cells(行, 3) = "無効の値"
End Select
Next 行
End Sub
ご存じの方もいると思いますが、実は上記回答例には隙があります。
Dim BMI As Double
Dim 行 As Integer
Dim 上端 As Integer
Dim 下端 As Integer
上端 = 2
下端 = 16
For 行 = 上端 To 下端
BMI = Cells(行, 3) / (Cells(行, 2) / 100) ^ 2
Cells(行, 4) = BMI
If BMI < 18.5 Then
Cells(行, 5) = "低体重(痩せ型)"
ElseIf 18.5 <= BMI And BMI < 25 Then
Cells(行, 5) = "普通体重"
ElseIf 25 <= BMI And BMI < 30 Then
Cells(行, 5) = "肥満(1度)"
ElseIf 30 <= BMI And BMI < 35 Then
Cells(行, 5) = "肥満(2度)"
ElseIf 35 <= BMI And BMI < 40 Then
Cells(行, 5) = "肥満(3度)"
ElseIf BMI >= 40 Then
Cells(行, 5) = "肥満(4度)"
End If
Next 行
End Sub
Dim BMI As Double
Dim 行 As Integer
Dim 上端 As Integer
Dim 下端 As Integer
上端 = 2
下端 = 16
For 行 = 上端 To 下端
BMI = Cells(行, 3) / (Cells(行, 2) / 100) ^ 2
Cells(行, 4) = BMI
Select Case BMI
Case Is < 18.5
Cells(行, 5) = "低体重(痩せ型)"
Case Is < 25
Cells(行, 5) = "普通体重"
Case Is < 30
Cells(行, 5) = "肥満(1度)"
Case Is < 35
Cells(行, 5) = "肥満(2度)"
Case Is < 40
Cells(行, 5) = "肥満(3度)"
Case Is >= 40
Cells(行, 5) = "肥満(4度)"
End Select
Next 行
End Sub