i have the following piece of code:

```
Function MyLookup(var1 As Variant, range1 As Range, var2 As Integer) As Double
MyLookup = Application.WorksheetFunction.VLookup(var1, range1, var2, False)
End Function
```

I use this function to calculate some of the parameters in the following function

```
Function Test(IntMethod As String, CFDate As Date, ValDate As Date, _
CF As Double, RepFreq As Integer, DiscToDate As String, _
DiscType As String) As Double
Dim InterpPeriod As Double, PrevDateRate As Double, _
CurrDateRate As Double, PrevCurvMat As Integer, _
CurrCurvMat As Integer, rate As Double
Dim Yield_Curves As Range, PrevValDate As Date
Set Yield_Curves = DISC_CFS.Range("Yield_Curves")
PrevValDate = Last_Period(ValDate, CFDate, RepFreq)
'-----------------------------------------------------
InterpPeriod = Application.WorksheetFunction.YearFrac(CFDate, ValDate, 1)
PrevCurvMat = YearsDiff(ValDate, CFDate)
CurrCurvMat = YearsDiff(ValDate, CFDate) + 1
PrevDateRate = MyLookup(PrevValDate, Yield_Curves, 2)
CurrDateRate = MyLookup(ValDate, Yield_Curves, 2)
```

when i get to MyLookup function, the range is not recognised and it exits the function.

Any hints?

thank you in advance!

I have finally managed to resolve the issue. The error was in one of my lookup variables, which was a date. The date should be converted to long type.

the correct code is the following:

```
Function MyLookup(var1 As Variant, range1 As Range, var2 As Integer) As Double
MyLookup = Application.WorksheetFunction.VLookup(var1, range1, var2, False)
End Function
```

And for the main code:

```
Function Test(IntMethod As String, CFDate As Date, ValDate As Date, _
CF As Double, RepFreq As Integer, DiscToDate As String, _
DiscType As String) As Double
Dim InterpPeriod As Double, PrevDateRate As Double, _
CurrDateRate As Double, PrevCurvMat As Integer, _
CurrCurvMat As Integer, rate As Double
Dim Yield_Curves As Range, PrevValDate As Date
Set Yield_Curves = DISC_CFS.Range("Yield_Curves")
PrevValDate = Last_Period(ValDate, CFDate, RepFreq)
'-----------------------------------------------------
InterpPeriod = Application.WorksheetFunction.YearFrac(CFDate, ValDate, 1)
PrevCurvMat = YearsDiff(ValDate, CFDate)
CurrCurvMat = YearsDiff(ValDate, CFDate) + 1
PrevDateRate = MyLookup(CLng(PrevValDate), Yield_Curves, 2)
CurrDateRate = MyLookup(CLng(ValDate), Yield_Curves, 2)
```

thank you for the provided answers and assistance