Consulting

Results 1 to 3 of 3

Thread: How to use previous row's Beginning Balance in calculation

  1. #1
    VBAX Regular
    Joined
    Mar 2019
    Posts
    6
    Location

    How to use previous row's Beginning Balance in calculation

    Weekly Payment Period Opening Balance Payment (Bi-Weekly) Principle Paid Interest Paid Lease Buyout Price
    1 $30,000.00 $215.52 $215.52 $0.00 $29,784.48
    2 $29,784.48 $215.52 $32.23 $183.29 $29,752.25
    3 $29,752.25 $215.52 $215.52 $0.00 $29,536.73
    4 $29,536.73 $215.52 $33.76 $181.76 $29,502.97
    5 $29,502.97 $215.52 $215.52 $0.00 $29,287.45
    6 $29,287.45 $215.52 $35.29 $180.23 $29,252.16
    7 $29,252.16 $215.52 $215.52 $0.00 $29,036.63
    8 $29,036.63 $215.52 $36.83 $178.69 $28,999.80

    I need to use the $30,000 when calculating intComp in period 2. I'm assuming I must change something in the intComp formula.
    For rowNum = 1 To loanLife * 26
    If (outRow + rowNum) Mod 2 = 0 Then
        intComp = 0
    Else
        intComp = yrBegBal * intRate / 13
    End If
    
    
        princRepay = biweeklyPmnt - intComp
        yrEndBal = yrBegBal - princRepay
        shtLoanAmort.Cells(outRow + rowNum, 1).Value = rowNum  'Year number
        shtLoanAmort.Cells(outRow + rowNum, 2).Value = yrBegBal
    Attached Files Attached Files

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Maybe


    For rowNum = 1 To loanLife * 26
    
    If (outRow + rowNum) Mod 2 = 0 Then
        intComp = 0
    
    Else
        If rowNum = 1 Then
            intComp = yrBegBal * intRate / 13
        Else
            intComp = shtLoanAmort.Cells(outRow + rowNum - 1, 2).Value * intRate / 13
        End If
    
    End If
    
        princRepay = biweeklyPmnt - intComp
        yrEndBal = yrBegBal - princRepay
        shtLoanAmort.Cells(outRow + rowNum, 1).Value = rowNum  'Year number
        shtLoanAmort.Cells(outRow + rowNum, 2).Value = yrBegBal
        shtLoanAmort.Cells(outRow + rowNum, 3).Value = biweeklyPmnt
        shtLoanAmort.Cells(outRow + rowNum, 4).Value = princRepay
        shtLoanAmort.Cells(outRow + rowNum, 5).Value = intComp
        shtLoanAmort.Cells(outRow + rowNum, 6).Value = yrEndBal 'Lease buyout price
        yrBegBal = yrEndBal
    Next rowNum
    


    As a side note, without an explicit "As Double" things like intRate as Dim-ed as Variant

    Dim intRate, initLoanAmnt, loanLife As Double
    Dim yrBegBal, yrEndBal
    Dim biweeklyPmnt, intComp, princRepay
    Dim outRow, rowNum, outSheet

    Suggest

    Dim intRateAs Double, initLoanAmnt As Double, loanLife As Double
    Dim yrBegBal As Double, yrEndBal As Double
    Dim biweeklyPmnt As Double, intComp As Double, princRepay As Double
    Dim outRow As Long, rowNum As Long
    DIm outSheet As String
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular
    Joined
    Mar 2019
    Posts
    6
    Location
    Quote Originally Posted by Paul_Hossler View Post
    Maybe


    For rowNum = 1 To loanLife * 26
    
    If (outRow + rowNum) Mod 2 = 0 Then
        intComp = 0
    
    Else
        If rowNum = 1 Then
            intComp = yrBegBal * intRate / 13
        Else
            intComp = shtLoanAmort.Cells(outRow + rowNum - 1, 2).Value * intRate / 13
        End If
    
    End If
    
        princRepay = biweeklyPmnt - intComp
        yrEndBal = yrBegBal - princRepay
        shtLoanAmort.Cells(outRow + rowNum, 1).Value = rowNum  'Year number
        shtLoanAmort.Cells(outRow + rowNum, 2).Value = yrBegBal
        shtLoanAmort.Cells(outRow + rowNum, 3).Value = biweeklyPmnt
        shtLoanAmort.Cells(outRow + rowNum, 4).Value = princRepay
        shtLoanAmort.Cells(outRow + rowNum, 5).Value = intComp
        shtLoanAmort.Cells(outRow + rowNum, 6).Value = yrEndBal 'Lease buyout price
        yrBegBal = yrEndBal
    Next rowNum
    


    As a side note, without an explicit "As Double" things like intRate as Dim-ed as Variant

    Dim intRate, initLoanAmnt, loanLife As Double
    Dim yrBegBal, yrEndBal
    Dim biweeklyPmnt, intComp, princRepay
    Dim outRow, rowNum, outSheet

    Suggest

    Dim intRateAs Double, initLoanAmnt As Double, loanLife As Double
    Dim yrBegBal As Double, yrEndBal As Double
    Dim biweeklyPmnt As Double, intComp As Double, princRepay As Double
    Dim outRow As Long, rowNum As Long
    DIm outSheet As String
    My apologies, I was actually able to figure it out with one line of code added:
    For rowNum = 1 To loanLife * 26
    If (outRow + rowNum) Mod 2 = 0 Then
        intComp = 0
    Else
        intComp = shtLoanAmort.Cells(outRow + rowNum, 2).Offset(-1).Value * intRate / 13 <<<<<<<<<<<<<
        
    End If
    Just changed the intComp formula. Guess it is pretty close to yours!
    Thanks so much for the help though!!

Tags for this Thread

Posting Permissions

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