Looping problem

G

Guest

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.
 
T

Trevor Shuttleworth

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
 
G

Guest

That did it. Thanks. Sleeping Bear

Trevor Shuttleworth said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top