The Student Room Group

VBA Loop problem

I'm trying to create a portion of a code which loops the programme, if certain conditions are not met.

I get a compile error saying .. Sub or Function not defined?


Period = InputBox("How many years do you wish to borrow?(1-25 Years)", , "10")
Cells(4, 9) = Period

'___________| Create Period Warning |_______________'

If Period > 25 Then
MsgBox "Your period should be between 1 to 25 Years", _
vbOKCancel, "WARNING!"

ElseIf Period < 1 Then
MsgBox "Your period should be between 1 to 25 Years", _
vbOKCancel, "WARNING!"

LoopUntil 1 < Period < 25
End If
Reply 1
That's not how you use an msgbox

Posted from TSR Mobile
Original post by Async
That's not how you use an msgbox


Any assistance would be appreciated
Reply 3
MsgBox("Your period should be between 1 to 25 Years", vbOKCancel, "WARNING!")
Original post by Async
MsgBox("Your period should be between 1 to 25 Years", vbOKCancel, "WARNING!")


Both methods for MsgBoxing work for me I suppose, with regards to the looping side, any ideas?

Do you think I can maybe create a GoTo scenario if the conditions aren't met? It's just defining the conditions which seem to be the problem?

I was thinking maybe:

If 1 < Period < 25 then GoTo [Next Part Of Code]

Else

GoTo [Initial Input Box]

The logic makes sense in my head, I just can't seem to figure it out on the VBA


Do you think that could work? Or something along those lines
Reply 5
Never ever ever use GoTo statements. They're considered bad programming practice.
Original post by Async
Never ever ever use GoTo statements. They're considered bad programming practice.


I'm unsure how to correctly loop this section?
Reply 7
A do untill loop must be need a Do.

E.g.



Dim x As Integer = 5

Do
x = x + 1
Loop Untill x > 50

Quick Reply

Latest

Trending

Trending