How to implement =Lookup function in VBA Excel?

Viewed 64

I have the following table:

Lookup Function

the lookup funcion in my case gives me the dates (06/08/2018) rate of 3.5% as this date falls in between the dates in the lookup table. I am struggling to produce same function in vba.

Function GetDateRate(dateValue As Date, dateRange As Range, valuesRange As Range)

    GetCurrentRate = Application.WorksheetFunction.Lookup(2, 1 / (dateRange <= dateValue), valuesRange)

End Function

But unfortunatly it fails... how can I fix that?

1 Answers

Found the solution to the problem:

enter image description here

    Set d = Range("G2")
Set TABLERANGE = Range("$D$2:$E$8") ' range of the table to explore

Range("H2").Value = Application.WorksheetFunction.VLookup(d, TABLERANGE, 2, True)
Related