贷款摊销时间表

时间:2012-08-13 12:27:00

标签: excel-vba vba excel

我需要生成贷款表,利率为8%,贷款期限为15年,初始贷款金额为200,000英镑。我在excel 2010上使用了下面的VBA代码,但它没有正确显示表格,这是我用过的代码;

Sub LoanSchedule()

Dim intRate, loanLife, initLoan, payment

intRate = InputBox("Input Interest rate:")
loanLife = InputBox("Input Loan life:")
initLoan = InputBox("Input Loan amount:")

Cells(4, 2).Value = intRate
Cells(5, 2).Value = loanLife
Cells(6, 2).Value = initLoan

payment = Pmt(intRate, loanLife, -initLoan)

'Year-beg Bal    Annual Payment  Interest Component  Prinicipal Repaid   Year-end Bal
 Dim yearBegBal, intComp, prinComp, yearEndBal

outRow = 10
yearBegBal = LoanAmtBal

For rowNum = 1 To loanLife
intComp = yearBegBal * intRate
prinComp = payment - intComp
yearEndBal = yearBegBal - prinComp

Cells(outRow + rowNum, 1).Value = rowNum
Cells(outRow + rowNum, 2).Value = yearBegBal
Cells(outRow + rowNum, 3).Value = payment
Cells(outRow + rowNum, 4).Value = intComp
Cells(outRow + rowNum, 5).Value = prinComp
Cells(outRow + rowNum, 6).Value = yearEndBal

yearBegBal = yearEndBal
Next rowNum

End Sub

由于我是VBA的初学者,有人可以帮助我。

2 个答案:

答案 0 :(得分:1)

LoanAmtBal的值未定义并直接使用,我认为这会导致问题......

yearBegBal = LoanAmtBal

答案 1 :(得分:0)

以下是OP试图做的工作版本......我自己需要它。

<?php 
 sort($this->system->produk);
 foreach ($this->system->produk as $pr_key=>$pr_val):
           if ($pr_val->status == 'on'):?>
          <li>
            <a href="<?php echo site_url(str_replace('_','-',$pr_key));?>"><?php echo $pr_val->nama;?></a>
          </li>
          <?php endif;?>
  <?php endforeach;?>