If/Then/Else with Comparison operators : Comparison Operators « Language Basics « VBA / Excel / Access / Word






If/Then/Else with Comparison operators

 
Sub NumberGuess()
    Dim userGuess As Integer
    Dim answer As Integer
    answer = Rnd * 10
    userGuess = 12
    If (userGuess > answer) Then
        MsgBox ("Too high!")
        MsgBox ("The answer is " & answer)
    End If
    If (userGuess < answer) Then
        MsgBox ("Too low!")
        MsgBox ("The answer is " & answer)
    End If
    If (userGuess = answer) Then MsgBox ("You got it!")
End Sub

 








Related examples in the same category

1.Comparison operators in VBA
2.Select Case with Comparison operators
3.<> operator