I would like to write a user defined function that returns the value in a range given a series ID and a date.
The range looks something like this
I would like the function call =getParam("B",1/07/2005,Parameters) to return 22.
To do this, I am using a couple of =MATCH functions to find the correct row and column and then will use an =INDEX function to return the correct value. My function (not complete) is below.
The problem:
When I specify =MATCH(1/07/2005,A1:A11,0) in a normal Excel cell I get the correct row index of 6, but when I incorporate this inside my VBA function as per below, I get a #VALUE! error.
Any ideas?
Function getParam(Series As String, StartDate As Date, Parameters As Range)
Dim IndexRow, IndexColumn As Integer
IndexRow = Application.WorksheetFunction.Match(StartDate, Parameters.Columns(1), 0)
IndexColumn = Application.WorksheetFunction.Match(Series, Parameters.Rows(1), 0)
getParam = IndexRow
End Function

