The Student Room Group

VBA Loop

I'm trying to create a code in VBA and I'm stuck where the question mark is. I'm saying if the BegBal Value is less than 1000, a message box should appear and if no is ticked it should loop back to the input box where another value can be entered, what can I type there to make that happen.

Code

BegBal = InputBox("what's your beginning balance?", "Borrow Amount", 100000)
Cells(1, 9) = BegBal
If BegBal < 1000 Then MsgBox "are you sure the loan's worth it", vbYesNno, "Checking"
If msgReply = vbNo Then ?????
Reply 1
Original post by Abdul-Karim
I'm trying to create a code in VBA and I'm stuck where the question mark is. I'm saying if the BegBal Value is less than 1000, a message box should appear and if no is ticked it should loop back to the input box where another value can be entered, what can I type there to make that happen.

Code

BegBal = InputBox("what's your beginning balance?", "Borrow Amount", 100000)
Cells(1, 9) = BegBal
If BegBal < 1000 Then MsgBox "are you sure the loan's worth it", vbYesNno, "Checking"
If msgReply = vbNo Then ?????


Use a Do While loop.


Do
BegBal = InputBox("what's your beginning balance?", "Borrow Amount", 100000)
Cells(1, 9) = BegBal

If BegBal < 1000 Then
msgReply = MsgBox("Are you sure the loan's worth it?", vbYesNno, "Checking")
Else
Exit While
End IF

Loop Until msgReply = vbYes


Next time learn the language.
Original post by Async
Use a Do While loop.


Do
BegBal = InputBox("what's your beginning balance?", "Borrow Amount", 100000)
Cells(1, 9) = BegBal

If BegBal < 1000 Then
msgReply = MsgBox("Are you sure the loan's worth it?", vbYesNno, "Checking")
Else
Exit While Exit Do
End IF

Loop Until msgReply = vbYes


Next time learn the language.


Thank you, this is my first week trying to learn to use VBA (so I'm an nooby), that's why I'm slow, I've never programmed before.

If it's not a bother, could you just briefly explain what your code just said in terms of the logic, as it works. Surely be of use to me.

Also think that's a mistake.
(edited 9 years ago)
Reply 3
Original post by Abdul-Karim
Thank you, this is my first week trying to learn to use VBA (so I'm an nooby), that's why I'm slow, I've never programmed before.

If it's not a bother, could you just briefly explain what your code just said in terms of the logic, as it works. Surely be of use to me.

Also think that's a mistake.


Yeah I forgot it was a Exit Do. I coded that of the top of my head. Anyway.

Basically, the code will keep looping msgReply = vbYes. The loop will execute all the code in the body of the do loop.
I suggest you learn do loops
Original post by Async
Yeah I forgot it was a Exit Do. I coded that of the top of my head. Anyway.

Basically, the code will keep looping msgReply = vbYes. The loop will execute all the code in the body of the do loop.
I suggest you learn do loops


Alright, thanks bro! Will do that now :rolleyes:

Any good resources you recommend?
Reply 5
https://www.thenewboston.com/videos.php?cat=39
Is good enough to get you started.
Original post by Async
https://www.thenewboston.com/videos.php?cat=39
Is good enough to get you started.


Should do, many thanks :biggrin:

Quick Reply

Latest

Trending

Trending