I need to create a macro that completes the following tasks.
1) Ask for the current car speed using an input box and store this value in a variable.
2) Using one If-Then-ElseIf structure output a message based on the speed.
This is what I have ...
Option Explicit
Sub question1()
Dim Speed As String
Speed = InputBox("What is your current car speed?")
Dim spd As Integer
If (spd < 0) Then
msgbox "this is an invalid speed"
ElseIf (spd > 0 And spd <= 54) Then
msgbox "You are driving too slowly"
ElseIf (spd >= 55 And spd <= 65) Then
msgbox "Your speed is fine"
ElseIf (spd >= 66 And spd <= 70) Then
msgbox "You are driving a little fast, but are probably okay"
Else
msgbox "You are driving too fast"
End If
End Sub
I keep getting "You are driving too fast" as my msgbox no matter what I input. What is the fix here? Thanks.
1) Ask for the current car speed using an input box and store this value in a variable.
2) Using one If-Then-ElseIf structure output a message based on the speed.
This is what I have ...
Option Explicit
Sub question1()
Dim Speed As String
Speed = InputBox("What is your current car speed?")
Dim spd As Integer
If (spd < 0) Then
msgbox "this is an invalid speed"
ElseIf (spd > 0 And spd <= 54) Then
msgbox "You are driving too slowly"
ElseIf (spd >= 55 And spd <= 65) Then
msgbox "Your speed is fine"
ElseIf (spd >= 66 And spd <= 70) Then
msgbox "You are driving a little fast, but are probably okay"
Else
msgbox "You are driving too fast"
End If
End Sub
I keep getting "You are driving too fast" as my msgbox no matter what I input. What is the fix here? Thanks.