View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Do Until Inputbox = loop count

Sub ABC()
Dim QCount As Long, qValue As Long
Dim Ans As Variant
Dim Message, Title, Default
Message = "Please enter the number of the current quarter (1 to 4)"
Title = "Enter Quarter"
Default = "1"

Ans = Application.InputBox(Message, _
Title, Default, Type:=2)
If TypeName(Ans) = "Boolean" Then Exit Sub
qValue = Int(Ans)
If qValue < 1 Or qValue 4 Then
MsgBox "Must be between 1 and 4 inclusive"
Exit Sub
End If
QCount = 0
Do
QCount = QCount + 1
Debug.Print QCount
'my code here
Loop Until QCount = qValue

End Sub


worked for me.

--
Regards,
Tom Ogilvy


"ewan7279" wrote:

Hi all,

I cannot work out why this isn't working. The user inputs a number from 1
to 4 into an inputbox, and I want the macro to loop for this number of times
(if 1 is entered, an if statement avoids this loop).

My code is as below, but the loop just keeps on going for any number
entered...

Dim Message, Title, Default
Message = "Please enter the number of the current quarter (1 to 4)"
Title = "Enter Quarter"
Default = "1"

qvalue = InputBox(Message, Title, Default)

Do Until QCount = qvalue
QCount = QCount + 1
'my code here
Loop

Any ideas?
Thanks,
Ewan.