In my function I am trying to pass two dates to a analysis toolpak -vba function (yearfrac). This function (i think) think takes serial dates as inputs. I get an error when I pass my two dates to the function.
My function is below. What is the best way to pass to serial dates to a function and have the yearfrac function (or any date function) work with those two dates?
Do I really need to take each date and use the DATE function? My function should calculate the time in years between two dates and then perform an operation using that difference and then return the results.
Thanks,
Jeff
Function dr_eq20(Kr, Tm As Date, T1 As Date) As Double
Dim T As Double
Dim Month_m, Day_m, Year_m, Month_1, Day_1, Year_1 As Integer
Dim Yearfrac As Excel.Application
Month_m = Month(Tm)
Day_m = Day(Tm)
Year_m = Year(Tm)
Month_1 = Month(T1)
Day_1 = Day(T1)
Year_1 = Year(T1)
T=Yearfrac(Date(year_1, month_1, day_1),Date(year_m, month_m, day_m),1)
'T = Yearfrac(T1, Tm, 1)
dr_eq20 = (1 - Exp(-Kr * T)) / Kr
End Function
My function is below. What is the best way to pass to serial dates to a function and have the yearfrac function (or any date function) work with those two dates?
Do I really need to take each date and use the DATE function? My function should calculate the time in years between two dates and then perform an operation using that difference and then return the results.
Thanks,
Jeff
Function dr_eq20(Kr, Tm As Date, T1 As Date) As Double
Dim T As Double
Dim Month_m, Day_m, Year_m, Month_1, Day_1, Year_1 As Integer
Dim Yearfrac As Excel.Application
Month_m = Month(Tm)
Day_m = Day(Tm)
Year_m = Year(Tm)
Month_1 = Month(T1)
Day_1 = Day(T1)
Year_1 = Year(T1)
T=Yearfrac(Date(year_1, month_1, day_1),Date(year_m, month_m, day_m),1)
'T = Yearfrac(T1, Tm, 1)
dr_eq20 = (1 - Exp(-Kr * T)) / Kr
End Function