I have this code, and it works:
Sub try3()
Dim dates(1 To 2) As Date
Dim values(1 To 2) As Double
Dim TIR As Double
dates(1) = #1/1/2015#
dates(2) = #1/1/2016#
values(1) = -1000
values(2) = 1101
TIR = Application.WorksheetFunction.xirr(values, dates)
End Sub
However, if I change the dates, for example, to
dates(1) = #1/15/2015#
dates(2) = #1/15/2016#
, then I get an error 1004:
"Property Xirr of class WorksheetFuntion could not be obtained".
My computer date format is european (dd/mm/yyyy). If I change it to american (mm/dd/yyyy), then my code works.
I would like to keep the european format in my system, and I would like my code to be runnable from any computer, regardless of their system's date format
I have tried to define the dates as follows, but I get the same error.
dates(1) = DateSerial(2015, 1, 15)
dates(2) = DateSerial(2016, 1, 15)
Any idea how to make VBA understand dates while keeping the european format in my computer?
Thank you