Xoolmonster

New Member
Joined
May 19, 2019
Messages
15
Hi guys,

I need help with a VBA macro that I’m supposed to finish for a course. The instructions for the macro is:

“Build a macro with a input box within a loop that asks the end user to put in numbers until the sum of numbers exceeds 100 then it ends and a message box appears which gives the sum of the numbers.”

How would one merits a macro like that?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Do you know how to build a loop?

Do you know how to terminate the loop?

Do you know how to use the inputbox?

Do you know how to use variables?

Do you know how to increment the variable?

If you know these things, the code should be simple=. If you don't, I suggest you go back to your class and tell them that you don't understand enough to complete the task, and seek help there?

We are not a homework service.
 
Upvote 0
Do you know how to build a loop?

Do you know how to terminate the loop?

Do you know how to use the inputbox?

Do you know how to use variables?

Do you know how to increment the variable?

If you know these things, the code should be simple=. If you don't, I suggest you go back to your class and tell them that you don't understand enough to complete the task, and seek help there?

We are not a homework service.

I know how and I was just asking for help. I suspected getting a response like this. Thanks a lot ?
 
Upvote 0
How far have you got with creating the macro?
If you post what you have done so far, it would help.
 
Upvote 0
How far have you got with creating the macro?
If you post what you have done so far, it would help.

I’m sorry to disappoint but I haven’t even started creating it yet. This macro question has been asked in exams before, but there’s no clear solutions for it in the course material. It’s supposed to work as a bonus question in the exam so no big deal in that regard.
 
Upvote 0
As this is a homework question I am not going to supply the code, but will happily point you in the right direction if you get stuck.
 
Upvote 0
Code:
Sub Loop_Test()
    Do Until iTotal > 100
        i = CInt(InputBox("Enter a number.", "Current Total = " & iTotal))
        iTotal = iTotal + i
    Loop
    MsgBox "Your final total is: " & iTotal, vbOKOnly, "Final Total"
End Sub

For the record, your original post was worded so that we assumed you simply wanted help accomplishing this yourself. Which is why nobody had provided the code for you at first. I think you had experienced coders eager to teach you to do this yourself. This is your homework after all. That being said, this accomplishes your task.

I really do hope you take the time to understand what was written for the sake of your education.
And I encourage you to ask questions about how this code works. We will be happy to help.

***As another note, I am not sure if you have any 'stability' requirements for this. But that code is very unstable as written (for example, entering anything other than a number in the input box will cause an error without some kind of data validation catch.***
 
Last edited:
Upvote 0
@Steve_
Nobody supplied the code as this is a homework question and most members prefer not do do other peoples homework, as it is a form of cheating.
 
Upvote 0
@Steve_
Nobody supplied the code as this is a homework question and most members prefer not do do other peoples homework, as it is a form of cheating.


I understand your position and i respect it. It is a totally moral, responsible, respectable, and commendable position to take. That being said, I on the other hand do not feel it is my place to determine or question how anyone does or does not do their homework. I only hope that my code is used by the requester to better their own understanding of the language. I provide the code. How they use it is up to them. I am not here to make moral determinations. I hope you can respect my position on the matter.

This thread feels dangerously close to becoming off topic. I would prefer to focus on code.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,530
Messages
6,114,163
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top