Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default endless loop - using input box

In Excel VBA...

Ok I'm writing a program that asks the user to input a number. If it
is not a valid number, they get an error and they can either "retry"
or "cancel"

now I just need to figure out how to put this in a loop, so they can
keep clicking "retry" if necessary or exit the sub if they click
cancel. however the loop I tried didn't work...it goes into endless
loop. Any suggestions? Thanks


If Sheets("Sales").Range("B1").Text = "#N/A" Then
'Checks for invalid number'
Output = MsgBox("You have entered an invalid Part
Number", _
vbRetryCancel, "Invalid Number")

Do
temp = Val(Output)
If temp = vbCancel Then ' User chose Cancel.
Exit Sub 'exit and clear.

ElseIf temp = vbRetry Then 'user chose retry
partNum = InputBox("Please enter the part number",
"Part Number", 0)

End If

Loop While Sheets("Sales").Range("B1").Text = "#N/A"

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default endless loop - using input box

Try:

partNum = InputBox("Please enter the part number", "Part Number",
0)

Sheets("Sales").Range("B1").Value = PartNum

While Sheets("Sales").Range("B1").Text = "#N/A"

Output = MsgBox("You have entered an invalid Part Number", _
vbRetryCancel, "Invalid Number")

temp = Val(Output)
If temp = vbCancel Then ' User chose Cancel.
Exit Sub 'exit and clear.

Loop


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default endless loop - using input box

Cleaner Still:

partNum = InputBox("Please enter the part number", "Part Number",
0)

Sheets("Sales").Range("B1").Value = PartNum

While Sheets("Sales").Range("B1").Text = "#N/A"

Output = MsgBox("You have entered an invalid Part Number",
vbRetryCancel, "Invalid Number")

If Val(Output) = vbCancel Then Exit Sub

Loop

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
Getting endless loop on DoUntil excelnut1954 Excel Programming 3 October 11th 06 09:18 PM
Endless loop freddie mac Excel Programming 2 August 1st 06 03:19 PM
endless loop help John Excel Programming 1 October 26th 05 04:51 PM
Endless loop? John Excel Programming 24 August 2nd 05 06:41 PM
Interrupting an endless loop davegb Excel Programming 3 March 17th 05 05:06 PM


All times are GMT +1. The time now is 12:41 AM.

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"