snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Function TOAMORTIZE(Principal As Double, StartDate As Date, EndDate As Date, FromDate As Date, ToDate As Date) As Double
Dim Accumulated As Double ' from assumptions
Dim TotalDays, CalcDays As Integer
Dim PerDay, PerDaySum, Results As Double
Dim EachDayDate() As Date
Dim EachDayValue() As Double
Dim n, i As Integer
PerDay = 0
PerDaySum = 0
Results = 0
ActiveCell.Value = ""
TotalDays = EndDate - StartDate + 1
ReDim EachDayDate(TotalDays)
ReDim EachDayValue(TotalDays)
CalcDays = ToDate - FromDate + 1
PerDay = Application.Round((Principal / TotalDays), 2)
For n = 0 To (TotalDays - 1)
EachDayDate(n) = StartDate + n
EachDayValue(n) = PerDay
PerDaySum = Application.Round((PerDaySum + PerDay), 2)
Next
If PerDaySum > Principal Then
EachDayValue(TotalDays - 1) = EachDayValue(TotalDays - 1) - Application.Round((PerDaySum - Principal), 2)
Else 'If PerDaySum "<" Principal Then
EachDayValue(TotalDays - 1) = PerDay + Application.Round((((PerDaySum - Principal) - (PerDay * i)) * -1), 2)
End If
For n = 0 To TotalDays - 1
If EachDayDate(n) >= FromDate And EachDayDate(n) <= ToDate Then
TOAMORTIZE = TOAMORTIZE + EachDayValue(n)
End If
Next
Erase EachDayDate ' Erasing the Array
Erase EachDayValue ' Erasing the Array
End Function
You do not have the required permissions to view the files attached to this post.
Last edited by zxcv on Mon Oct 01, 2012 5:20 pm, edited 2 times in total.