Using a Input Box Value in an if statement

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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!
 
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:
 
This looks like a formula, I'm looking for this in terms of a macro. Thanks
for the help though.
 
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
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top