Error 424 (object required) when using Application.Caller.Offset
I have written the following code to calculate the difference between two dates, which returns a Error 424 - Object required.
Public Function DateDifference() As Long
Dim Shift As integer
DateDifference=Datediff("d", Application.Caller.Offset(0,Shift), Application.Caller.Offset(0,Shift+1))
There are easier ways to do this, but I do need to reference the two cells with the dates in relative to the cell the function is called from. I also need to shift the two date cells along the row, hence the "shift" variable.
Even though it does calculate the difference, it breaks out at the DateDifference line and seems to have an issue with Application.Caller.Offset section. I can get it to work fully by giving it two dates explicitly.
Can someone please help me with the error.