Using a Input Box Value in an if statement

V

Vick

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!
 
M

Marcelo

Hi Vick,

try if(vdate=6,"true","false")
you just replace the "true" and "false" for you need.

hope this help.
regards from Brazil
Marcelo

"Vick" escreveu:
 
V

Vick

This looks like a formula, I'm looking for this in terms of a macro. Thanks
for the help though.
 
N

Nick Hodge

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
[email protected]
 
M

Marcelo

sorry, i did not notice that you were looking for a Macro

regards

"Vick" escreveu:
 
Top