View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Nick Hodge
 
Posts: n/a
Default Using a Input Box Value in an if statement

Vick

There are two types of inputbox (VBA's and Excel's). Excel's is prefixed
with Application and has slightly different parameters including what return
type in allows.

The VBA version returns a string, so if you are checking for an integer, you
should explicitly convert it using CInt(). The basic code below works

Sub ValueFromInputBox()
Dim vDate As String
vDate = InputBox("Enter a whole number", "Input")
If CInt(vDate) = 6 Then
MsgBox "True"
Else
MsgBox "False"
End If
End Sub


--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
www.nickhodge.co.uk
HIS


"Vick" wrote in message
...
I'm trying to create an If, then, else statment using the value of an
input
box.

So lets say the variable of my input box is vdate and it returns 6 how
would
I write the IF statement to true if vdate = 6. If VDATE = 6 then? What am
I
missing?

Thanks for your help!