View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
ewan7279 ewan7279 is offline
external usenet poster
 
Posts: 97
Default Do Until Inputbox = loop count

Thanks Joel!!

"Joel" wrote:

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


Do
qvalue = val(InputBox(Message, Title, Default))
Loop while (qvalue < 1) and (qvalue 4)

'my code here


"ewan7279" wrote:

Hi Mike,

Sorry, I should have included that I have already declared qvalue as an
integer variable and it still does not work. The inputbox value (qvalue)
works in an if statement before the loop, and there is a validation also to
check the value entered does not exceed 4, with a msgbox resulting if it
does. It just doesn't work in this loop...

Any ideas?
Thanks.

"Mike H" wrote:

Hi,

Your inputbox is returning a text string so qvalue will never equal qcoount
hence the endless loop. Try this:-


Sub sonic()
Dim Message, Title, Default
Dim qvalue As Integer
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
MsgBox qcount
End Sub

Mike


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