A
Adrian
I have written this function - it works fine in the
immediate window of the VBA editor, but fails when I put
into a cell of a worksheet. I get #VALUE.
Why?
(Explanation - an area of the worksheet "modules" contains
a database which has multiple keyvalues. This function
allows you to specify in which column to look for a value,
then looksup the answer. kinda like "vlookup" with extra
flexibility.)
Function Minfo(lookupcol, lookupval, returncol)
Set src = Workbooks("Data.xls").Names
("Mdatabase").RefersToRange
toprow = src.Row
lastrow = src.Rows.Count + toprow - 1
'find lookupcol in toprow
lkcol = Workbooks("Data.xls").Worksheets("modules").Range
(toprow & ":" & toprow).Find(lookupcol).Column
'find returncol in toprow
rtncol = Workbooks("Data.xls").Worksheets("modules").Range
(toprow & ":" & toprow).Find(returncol).Column
'find lookupval in lookupcol and give its row
lkrow = Workbooks("Data.xls").Worksheets("modules").Range
(Cells(1, lkcol), Cells(lastrow, lkcol)).Find
(lookupval).Row
Minfo = Workbooks("Data.xls").Worksheets("modules").Cells
(lkrow, rtncol)
End Function
immediate window of the VBA editor, but fails when I put
into a cell of a worksheet. I get #VALUE.
Why?
(Explanation - an area of the worksheet "modules" contains
a database which has multiple keyvalues. This function
allows you to specify in which column to look for a value,
then looksup the answer. kinda like "vlookup" with extra
flexibility.)
Function Minfo(lookupcol, lookupval, returncol)
Set src = Workbooks("Data.xls").Names
("Mdatabase").RefersToRange
toprow = src.Row
lastrow = src.Rows.Count + toprow - 1
'find lookupcol in toprow
lkcol = Workbooks("Data.xls").Worksheets("modules").Range
(toprow & ":" & toprow).Find(lookupcol).Column
'find returncol in toprow
rtncol = Workbooks("Data.xls").Worksheets("modules").Range
(toprow & ":" & toprow).Find(returncol).Column
'find lookupval in lookupcol and give its row
lkrow = Workbooks("Data.xls").Worksheets("modules").Range
(Cells(1, lkcol), Cells(lastrow, lkcol)).Find
(lookupval).Row
Minfo = Workbooks("Data.xls").Worksheets("modules").Cells
(lkrow, rtncol)
End Function