VBA bug

wycyobm

New Member
Joined
Apr 5, 2017
Messages
11
Hi, I am trying to run my code but it stops at one point and it says invalid procedure call or argument.
Does anyone knows where is the problem? Thanks!


'Calculation of the annual payment
annualPmnt = Pmt(intRate, loanLife, -initLoanAmnt, , 0)
'Initialize beginning balance of the 1st year
yrBegBal = initLoanAmnt
'Loop to calculate and output year-by-year amortization table
For rowNum = 1 To loanLife
intComp = yeBegBal * intRate
princRepay = annualPmnt = intComp
yrEndBal = yrBegBal = princRepay
Cells(outRow + rowNum + 3, 3).Value = rowNum 'this is the year number
Cells(outRow + rowNum + 3, 4).Value = yeBegBal
Cells(outRow + rowNum + 3, 5).Value = annualPmnt
Cells(outRow + rowNum + 3, 6).Value = intComp
Cells(outRow + rowNum + 3, 7).Value = princRepay
Cells(outRow + rowNum + 3, 8).Value = yrEndBal
yrBegBal = yrEndBal
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
wycyobm,

Welcome to the MrExcel forum.

In order to assist you it would help us if you posted all of your macro code using code tags.

When posting VBA code, please use Code Tags - like this:

[code=rich]

'Paste your code here.

[/code]
 
Upvote 0
Hi, i have posted like a code.
It stops at annualPmnt = Pmt(intRate, loanLife, -initLoanAmnt, , 0)


Code:
intRate = Cells(2, 2).Value
loanLife = Cells(3, 2).Value
initLoanAmnt = Cells(4, 2).Value
'Here where make sure that the interest
'does not exceed 15%
If intRate > 0.15 Then
MsgBox "Interest rate cannot be greater than 15%"
End
End If
'********************************************
'Compute and output results
'********************************************
'Calculation of the annual payment
annualPmnt = Pmt(intRate, loanLife, -initLoanAmnt, , 0)
'Initialize beginning balance of the 1st year
yrBegBal = initLoanAmnt
'Loop to calculate and output year-by-year amortization table
For rowNum = 1 To loanLife
intComp = yeBegBal * intRate
princRepay = annualPmnt = intComp
yrEndBal = yrBegBal = princRepay
Cells(outRow + rowNum + 3, 3).Value = rowNum 'this is the year number
Cells(outRow + rowNum + 3, 4).Value = yeBegBal
Cells(outRow + rowNum + 3, 5).Value = annualPmnt
Cells(outRow + rowNum + 3, 6).Value = intComp
Cells(outRow + rowNum + 3, 7).Value = princRepay
Cells(outRow + rowNum + 3, 8).Value = yrEndBal
 
Upvote 0
wycyobm,

In order to assist you it would help us if you posted all of your macro code using code tags.


When posting VBA code, please use Code Tags - like this:

[code=rich]

Paste your code here.

[/code]
 
Upvote 0
Whats in cell B3 on the activesheet at the time this line runs:

Code:
loanLife = Cells(3, 2).Value
 
Upvote 0
what are your values for interest, loan life and loan amount? these should all be Doubles..... might you have ne of those values as a string?
 
Upvote 0
Hi, I am trying to run my code but it stops at one point and it says invalid procedure call or argument.
Does anyone knows where is the problem? Thanks!


'Calculation of the annual payment
annualPmnt = WorksheetFunction.Pmt(intRate, loanLife, -initLoanAmnt, , 0)
'Initialize beginning balance of the 1st year
yrBegBal = initLoanAmnt
'Loop to calculate and output year-by-year amortization table
For rowNum = 1 To loanLife
intComp = yeBegBal * intRate
princRepay = annualPmnt = intComp
yrEndBal = yrBegBal = princRepay
Cells(outRow + rowNum + 3, 3).Value = rowNum 'this is the year number
Cells(outRow + rowNum + 3, 4).Value = yeBegBal
Cells(outRow + rowNum + 3, 5).Value = annualPmnt
Cells(outRow + rowNum + 3, 6).Value = intComp
Cells(outRow + rowNum + 3, 7).Value = princRepay
Cells(outRow + rowNum + 3, 8).Value = yrEndBal
yrBegBal = yrEndBal
Pmt is not a native VBA function... it is an Excel function, so you must use the WorksheetFunction object to get to it... try making the change I show in red above.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,574
Messages
6,131,492
Members
449,653
Latest member
aurelius33

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