![]() |
Looping problem
I have a macro that prompts for the quarter. I ask for 1, 2, 3, or 4 and go
on from that. Even with the message box specifying the desired input, some users are entering alpha or something else. I'm trying to create a loop that will give the user 4 chances to enter correctly and then use the default, regardless of what the user has entered. I keep getting a type mismatch error but when I change the variable to integer, alpha data causes it to stop. Any ideas? Here's the code I have now: Dim Q As Integer Q = 0 chk1 = False Do Until chk1 = True Dim z As String z = InputBox("Input quarter (1, 2, 3, or 4) to run. Default is 1.", , "1") If z = 1 Then qtr = Mar chk1 = True End If If z = 2 Then qtr = Jun chk1 = True End If If z = 3 Then qtr = Sep chk1 = True End If If z = 4 Then qtr = Dec chk1 = True End If If Q 3 Then MsgBox ("You've had 4 chances. I choose the default of '1' for you.") qtr = Mar chk1 = True End If Q = Q + 1 Loop Thanks. |
Looping problem
That did it. Thanks. Sleeping Bear
"Trevor Shuttleworth" wrote: Try: Sub test() Dim Q As Integer Q = 0 chk1 = False Do Until chk1 = True Dim z ' <<<<<< z = InputBox("Input quarter (1, 2, 3, or 4) to run. Default is 1.", , "1") Regards Trevor "Sleeping Bear" <Sleeping wrote in message ... I have a macro that prompts for the quarter. I ask for 1, 2, 3, or 4 and go on from that. Even with the message box specifying the desired input, some users are entering alpha or something else. I'm trying to create a loop that will give the user 4 chances to enter correctly and then use the default, regardless of what the user has entered. I keep getting a type mismatch error but when I change the variable to integer, alpha data causes it to stop. Any ideas? Here's the code I have now: Dim Q As Integer Q = 0 chk1 = False Do Until chk1 = True Dim z As String z = InputBox("Input quarter (1, 2, 3, or 4) to run. Default is 1.", , "1") If z = 1 Then qtr = Mar chk1 = True End If If z = 2 Then qtr = Jun chk1 = True End If If z = 3 Then qtr = Sep chk1 = True End If If z = 4 Then qtr = Dec chk1 = True End If If Q 3 Then MsgBox ("You've had 4 chances. I choose the default of '1' for you.") qtr = Mar chk1 = True End If Q = Q + 1 Loop Thanks. |
All times are GMT +1. The time now is 03:30 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com