Hi,
I'm creating a UDF in which I use WorksheetFunction.Match.
The Range I want to use is the first column of the user specified range.
I achieve this as follows (I am only including the relevant part of the function for simplicity's sake):
Function MyFunction(Lookup_Range As Range, Row_Header As Variant)
Dim DRow, TRow, BRow, LCol, RCol As Integer
Dim DSheet As String
DSheet = Lookup_Range.Parent.Name 'Gets sheet Name
TRow = Lookup_Range.Row 'Gets Top Row Number
BRow = TRow + Lookup_Range.Rows.Count - 1 'Gets Bottom Row Number
LCol = Lookup_Range.Column 'Gets Left Most Col Number
RCol = LCol + Lookup_Range.Columns.Count - 1 'Gets Right Most Col Number
DRow = WorksheetFunction.Match(Row_Header, Worksheets(DSheet).Range(Cells(TRow, LCol), Cells(BRow, LCol)), 0) 'For some reason this does not work????
'...
End Function
Does anyone know why that line does not work? Note that when I removed the sheet name it worked fine (as long as the lookup range was in the same sheet as the cell with the function)
Bookmarks