VBA Programming

posted by .

I'm trying to create a macro that asks for a loan between 1 dollar and 5 million, and returns different interest rates based on the amount of the loan. For some reason when I type in different loan amounts it automatically makes my rate ".1", when it should be say ".08", or ".11" because of the entered loan amount.
Heres my code so far:

Sub DetermineinterestIf()
Dim loan As Variant
Dim interest As Double
Do
loan = InputBox("Enter your desired loan amount, from 1 dollar to 5 million dollars.")
Loop Until IsNumeric(loan)
If loan < 1000000 Then interest = ".08"
If loan > 4000000 Then interest = ".11"
If 1000000 < loan < 4000000 Then interest = ".10"
MsgBox ("The loan amount was " & loan & " with an interest rate of " & interest & ".")
End Sub

Any ideas where I have gone wrong?

  • VBA Programming -

    First off, why use strings to specify a numeric (Double) value for interest?

    I learned VBA a while ago, but I think that

    If 1000000 < loan < 4000000 Then interest = .10

    is invalid syntax. Try

    If (1000000 < loan) and (loan < 4000000) Then interest = .10

    Or, you might try

    interest = 0.10
    If loan < 1000000 Then interest = .08
    If loan > 4000000 Then interest = .11

    That is, assume the interest will be .10, and only change it if the loan amount is too big or too small

    Or, if you find that you have to do other stuff depending on the interest rate, you could go whole-hog and say


    If loan < 1000000 Then
    interest = .08
    do 8% stuff
    Else If loan > 4000000 Then
    interest = .11
    do 11% stuff
    Else
    interest = .10
    do 10% stuff
    End If

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. math

    The annual interest rate for a customer’s loan of $425 is 15.75%. What is the total dollar amount to be repaid on the loan, including principle and interest, for the entire year?
  2. Math

    A person takes a simple interest loan at 7.5%. After 6 months, the amount of interest on the loan is $69.64. What was the amount of the loan?
  3. MATH

    Martin takes out a simple-interest loan at 7.5 %. After 6 months, the amount of interest on the loan is $69.64. What was the amount of the loan?
  4. eco

    Suppose a person pays $80 of annual interest on a loan that has a 5 percent annual interest rate. The loan amount is: A. $400. B. $1,600. C. $160. D. $85. 10. Suppose a loan customer is considering two alternative $22,000 loans. Loan …
  5. math

    Loan #1 Year Amount owed 1 $3796 2 $3942 3 $4088 Loan # 2 Year Amount owed 1 $977.53 2 $1036.18 3 1098.35 For loan #1 is simple interest. Loan #2 is compound interest How much was each loan originally Determine the future value of …
  6. math

    Loan #1 Year Amount owed 1 $3796 2 $3942 3 $4088 Loan # 2 Year Amount owed 1 $977.53 2 $1036.18 3 1098.35 For loan #1 is simple interest. Loan #2 is compound interest How much was each loan originally Determine the future value of …
  7. VBA programming

    How to get isnumeric function to display an "error" message when necessary. Sub DetermineinterestSelectCase() Dim loan As Variant Dim interest As Double loan = InputBox("Enter your desired loan amount, from 1 dollar to 5 million dollars.") …
  8. n nb

    The annual interest rate for a customer’s loan of $425 is 15.75%. What is the total dollar amount to be repaid on the loan, including principle and interest, for the entire year?
  9. math

    The annual interest rate for a customer’s loan of $425 is 15.75%. What is the total dollar amount to be repaid on the loan, including principle and interest, for the entire year?
  10. math

    The annual interest rate for a customer’s loan of $425 is 15.75%. What is the total dollar amount to be repaid on the loan, including principle and interest, for the entire year?

More Similar Questions