+ Reply to Thread
Results 1 to 12 of 12

Need some assistance with my syntax

  1. #1
    Registered User
    Join Date
    09-27-2022
    Location
    Philadelphia, PA
    MS-Off Ver
    2019
    Posts
    3

    Question Need some assistance with my syntax

    Hey guys, looking for some help on proper syntax for creating a function in the VBE of Excel. My apologies ahead of time, I am extremely new to this and the below problem is part of a Coursera course I am taking:



    When a loan of principal amount, P, is taken at an annual interest rate iwith a repayment period of n years, the following equation provides the monthly payment, A:

    FY1-6LYLEeiu9BLDf-7i5A_b9833a7ad547b30f277ed1717c0566bd_payment.png

    Create a VBA function called payment(P,i,n) that will output the monthly payment (A) based on the principal, annual interest rate, and lifetime of the loan.

    To check your answer, the monthly payment on a 20-year loan with principle $10,000 with an annual interest rate of 4.5% would be $63.26.



    The way I wrote this function is below. When I try to run it, I get a "Compile error: Expected Array" error message. I know what I have is incorrect, just need help figuring it out:

    Function payment(P As Double, i As Double, n As Double) As Double
    Dim A As Double
    A = (P(i / 12)) / (1 - (1 + (i / 12))) ^ (-n * 12)
    payment = A
    End Function

  2. #2
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: Need some assistance with my syntax

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,047

    Re: Need some assistance with my syntax

    Reason for compile error is that the P( is interpreted as an array rather than a multiplication

    Also I think you need to account for 4.5 being a percentage.


    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    09-27-2022
    Location
    Philadelphia, PA
    MS-Off Ver
    2019
    Posts
    3

    Re: Need some assistance with my syntax

    Thank you ByteMarks! Very much appreciated.

    Looks like that was the problem. And yes, also had to account for 4.5 being a percentage.

  5. #5
    Registered User
    Join Date
    09-27-2022
    Location
    Philadelphia, PA
    MS-Off Ver
    2019
    Posts
    3

    Re: Need some assistance with my syntax

    Apologies, but my next question is how do I get "payment" into a currency format? I'm trying to use the FormatCurrency function, but can't figure it out.

  6. #6
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,047

    Re: Need some assistance with my syntax

    Maybe change

    Payment = A to
    Please Login or Register  to view this content.
    or

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-02-2023
    Location
    Nigeria
    MS-Off Ver
    2010
    Posts
    4

    Re: Need some assistance with my syntax

    Hi, please how did you go about the accounting for the 4.5 as a percentage?
    Last edited by adokhai; 01-02-2023 at 09:23 PM.

  8. #8
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,543

    Re: Need some assistance with my syntax

    Please Login or Register  to view this content.
    Experience trumps academics every day of the week and twice on Sunday.

  9. #9
    Registered User
    Join Date
    01-02-2023
    Location
    Nigeria
    MS-Off Ver
    2010
    Posts
    4
    Quote Originally Posted by jolivanes View Post
    Please Login or Register  to view this content.
    Thanks a lot, but it isn't working for me.

    Function payment(P As Double, i As Double, n As Double) As Double
    Dim A As Double
    i = (i / 100)
    A = (P * i / 12) / (1 - (1 + i / 12) ^ (-n * 12))
    payment = A
    End Function

    This was how I did it, still giving me error message that "Function payment is incorrect"

  10. #10
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,364

    Re: Need some assistance with my syntax

    Works OK for me

    =payment(10000,4.5,20)

    returns 63.26
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  11. #11
    Registered User
    Join Date
    01-02-2023
    Location
    Nigeria
    MS-Off Ver
    2010
    Posts
    4

    Re: Need some assistance with my syntax

    Thanks a lot, I so appreciate the response. It's working for me now. However, when I try uploading it for grading I keep receiving an error message that the payment function is incorrect.
    Last edited by adokhai; 01-03-2023 at 08:39 PM.

  12. #12
    Registered User
    Join Date
    01-03-2023
    Location
    Pakistan
    MS-Off Ver
    2016
    Posts
    1

    Re: Need some assistance with my syntax

    I wrote the following syntax, but I am receiving an error message that payment function is incorrect.

    Function payment(P As Double, i As Double, n As Double) As Double
    Dim A As Double
    i = (i / 100)
    A = (P * (i / 12)) / (1 - (1 + i / 12) ^ (-n * 12))
    payment = A
    End Function

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Formula Syntax Assistance Required
    By robertguy in forum Excel General
    Replies: 5
    Last Post: 04-19-2018, 07:49 AM
  2. Replies: 3
    Last Post: 04-19-2017, 09:30 AM
  3. [SOLVED] Conditional Formatting Formula Syntax Assistance
    By robertguy in forum Excel General
    Replies: 3
    Last Post: 06-22-2016, 06:34 AM
  4. [SOLVED] Conditional Format Syntax Assistance
    By robertguy in forum Excel General
    Replies: 4
    Last Post: 04-19-2016, 10:55 AM
  5. [SOLVED] Assistance please?
    By http:// in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  6. Assistance please?
    By http:// in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 01:05 AM
  7. Assistance please?
    By http:// in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-06-2005, 04:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1