Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
User Input Of A Number
Why are there two "If"s, two "Then"s, zero "Else"s, and zero "En If"s??? (assuming all of that counts as one question) And how do I modify Ivan's solution to display a short error messag that a two or three digit number has NOT been input by user? Thanks for a response, Chuckles12 -- Chuckles12 ----------------------------------------------------------------------- Chuckles123's Profile: http://www.excelforum.com/member.php...fo&userid=1494 View this thread: http://www.excelforum.com/showthread.php?threadid=27517 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
User Input Of A Number
You could do something like:
Option Explicit Sub Tester() Dim Result Again: Result = Application.InputBox("Enter 2 or 3 digit number", Type:=1) If Result = False Then Exit Sub If Len(Result) 3 Or Len(Result) < 2 Then MsgBox "Not a 2 or 3 digit number" GoTo Again End If MsgBox Result End Sub Or maybe just put it in the message that's displayed: Option Explicit Sub Tester2() Dim Result Dim msg As String msg = "Enter 2 or 3 digit number" Again: Result = Application.InputBox(msg, Type:=1) If Result = False Then Exit Sub If Len(Result) 3 Or Len(Result) < 2 Then msg = "That's not correct" & vbLf & msg GoTo Again End If MsgBox Result End Sub There are two types of If statements. The first type is on one logical line (maybe on multiple physical lines if you use the continuation character (space underscore) If condition Then [statements] [Else elsestatements] The second is the block form: If condition Then [statements] [ElseIf condition-n Then [elseifstatements] ... [Else [elsestatements]] End If (I stole the examples from VBA's help.) And with block if's, you don't always need the Else portion: if someconditionistrue then msgbox "good job end if I sometimes put the "else" portion, but just have a comment. If somecondtionistrue then msgbox "good job" else 'do nothing end if But that's just a personal preference. Chuckles123 wrote: Why are there two "If"s, two "Then"s, zero "Else"s, and zero "End If"s??? (assuming all of that counts as one question) And how do I modify Ivan's solution to display a short error message that a two or three digit number has NOT been input by user? Thanks for a response, Chuckles123 -- Chuckles123 ------------------------------------------------------------------------ Chuckles123's Profile: http://www.excelforum.com/member.php...o&userid=14948 View this thread: http://www.excelforum.com/showthread...hreadid=275174 -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
show a number of rows based upon user input | Excel Discussion (Misc queries) | |||
Change color of cell after user has input a number | Excel Discussion (Misc queries) | |||
User Input Of A Number | Excel Programming | |||
User Input Of A Number | Excel Programming | |||
CODE to select range based on User Input or Value of Input Field | Excel Programming |