VBA Code Help Im new to this.

Alpacino

Well-known Member
Joined
Mar 16, 2011
Messages
511
hello everyone I have been practising using VBA and input Boxes.

I have this Code but I want to put in if answer is Greater than 10 then MsgBox wow thats alot. and if its less than 10 then MsgBox "Go to the travel Agents Pronto" how do I do this???

Thanks in advance
Alan

Sub Question3()
Num = InputBox("How many countries have you visited?")
MsgBox Num & ". Really that many, I never knew that!!"
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Something like:
Code:
Sub Question3()
  num = InputBox("How many countries have you visited?")
  Select Case num
    Case Is < 10
      MsgBox "Go to the travel Agents Pronto"
    Case Is > 10
      MsgBox num & ". Really that many, I never knew that!!"
  End Select
End Sub
 
Upvote 0
Code:
Sub Question3()
num = InputBox("How many countries have you visited?")
If num >= 10 Then
    MsgBox ("wow thats alot")
Else
    MsgBox ("go to the travel agents pronto")
End If

End Sub
 
Upvote 0
thank you for that!
How do I add another MsgBox e.g is countries visited is Greater than 20 then MsgBox "You must be Michael Palin"
 
Upvote 0
thank you for that!
How do I add another MsgBox e.g is countries visited is Greater than 20 then MsgBox "You must be Michael Palin"

an additon to the code above.

Code:
Sub Question3()
num = InputBox("How many countries have you visited?")
If num >= 20 Then
MsgBox ("You must be Michael Palin")
ElseIf num >= 10 Then
MsgBox ("wow thats alot")
Else
MsgBox ("go to the travel agents pronto")
    
End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top