Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
show a number of rows based upon user input P_R Excel Discussion (Misc queries) 1 April 22nd 08 08:03 AM
Change color of cell after user has input a number F7772 Excel Discussion (Misc queries) 3 August 29th 05 09:20 PM
User Input Of A Number Chuckles123[_48_] Excel Programming 0 November 11th 04 05:27 AM
User Input Of A Number Chuckles123[_43_] Excel Programming 2 November 4th 04 06:42 AM
CODE to select range based on User Input or Value of Input Field Sandi Gauthier Excel Programming 4 December 8th 03 03:22 PM


All times are GMT +1. The time now is 09:01 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"