Better way of handling dates?

jturn00

Board Regular
Joined
Jul 21, 2004
Messages
80
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
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Or call the function along the lines of the following:

Sub test()
MsgBox Nwdys
End Sub

Function Nwdys() As Long
Nwdys = Application.Run("ATPVBAEN.XLA!Networkdays", Date - 2, Date)
End Function
 
Upvote 0

Forum statistics

Threads
1,217,404
Messages
6,136,416
Members
450,010
Latest member
Doritto305

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