![]() |
InputBox Method Logic Problem
I am using the inputbox method to take a number from a user. I want th
inputbox to do the following: 1) if the user does not enter anything, exit sub 2) if the user picks a number 254, disallow it and start again 3) if user picks number <= 254 then proceed How do I set this code up so that if the user picks 254 then it wil take the user back the to the initial IF Statment? As modeled, it onl prompts them once and then proceeds with anwer. Dim NumberofColumns As Integer Dim BMax As Integer NumberofColumns = Application.InputBox(prompt:="Enter Number of 2 Elements", Type:=1) If NumberofColumns = False Then MsgBox ("Operation Canceled") Exit Sub ElseIf NumberofColumns 254 Then MsgBox ("You cannot enter a number bigger than 254. Tr again.") NumberofColumns = Application.InputBox(prompt:="Enter Number o 2D Elements", Type:=1) Else BMax = NumberofColumns End I -- Message posted from http://www.ExcelForum.com |
InputBox Method Logic Problem
The InputBox() returns a string; you might have to work with the Value()
function to get it converted.. HTH "ExcelMonkey " wrote in message ... I am using the inputbox method to take a number from a user. I want the inputbox to do the following: 1) if the user does not enter anything, exit sub 2) if the user picks a number 254, disallow it and start again 3) if user picks number <= 254 then proceed How do I set this code up so that if the user picks 254 then it will take the user back the to the initial IF Statment? As modeled, it only prompts them once and then proceeds with anwer. Dim NumberofColumns As Integer Dim BMax As Integer NumberofColumns = Application.InputBox(prompt:="Enter Number of 2D Elements", Type:=1) If NumberofColumns = False Then MsgBox ("Operation Canceled") Exit Sub ElseIf NumberofColumns 254 Then MsgBox ("You cannot enter a number bigger than 254. Try again.") NumberofColumns = Application.InputBox(prompt:="Enter Number of 2D Elements", Type:=1) Else BMax = NumberofColumns End If --- Message posted from http://www.ExcelForum.com/ |
InputBox Method Logic Problem
The following worked when I tested it.
Sub Test1() Dim NumberofColumns As Integer Dim BMax As Integer Dim InputErrorCheck As Boolean InputErrorCheck = False Do While InputErrorCheck = False NumberofColumns = Application.InputBox(prompt:="Enter Number of 2D Elements", Type:=1) If IsNumeric(NumberofColumns) Then If NumberofColumns <= 254 And NumberofColumns 0 Then ' I assumed to wanted more than zero - easily altered if not. InputErrorCheck = True End If End If If NumberofColumns = False Then MsgBox ("Operation Canceled") Exit Sub End If Loop MsgBox (NumberofColumns) End Sub -- Darren "ExcelMonkey " wrote in message ... I am using the inputbox method to take a number from a user. I want the inputbox to do the following: 1) if the user does not enter anything, exit sub 2) if the user picks a number 254, disallow it and start again 3) if user picks number <= 254 then proceed How do I set this code up so that if the user picks 254 then it will take the user back the to the initial IF Statment? As modeled, it only prompts them once and then proceeds with anwer. --- Message posted from http://www.ExcelForum.com/ |
All times are GMT +1. The time now is 05:18 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com