A
Adrian
Below is a macro function that works fine in the immediate
window, but gives #VALUE when I try to use it in a
worksheet.
I had this problem recently with an earlier version of
this macro and was advised to use Match instead of Find,
since apparently Find is known to fail in this fashion on
earlier versions of Excel.
This macro needs to work in Excel 97 onwards.
Function Sinfo(lookupkey, lookupval, rtnkey)
Set rng = Workbooks("data.xls").Worksheets
("students").Range("1:1")
lkcol = Application.WorksheetFunction.Match(lookupkey,
rng, 0)
rtncol = Application.WorksheetFunction.Match(rtnkey, rng,
0)
Set rng2 = Workbooks("data.xls").Worksheets
("students").Range(Cells(1, lkcol), Cells(65535, lkcol))
rtnrow = Application.WorksheetFunction.Match(lookupval,
rng2, 0)
Sinfo = Workbooks("data.xls").Worksheets("students").Cells
(rtnrow, rtncol)
End Function
window, but gives #VALUE when I try to use it in a
worksheet.
I had this problem recently with an earlier version of
this macro and was advised to use Match instead of Find,
since apparently Find is known to fail in this fashion on
earlier versions of Excel.
This macro needs to work in Excel 97 onwards.
Function Sinfo(lookupkey, lookupval, rtnkey)
Set rng = Workbooks("data.xls").Worksheets
("students").Range("1:1")
lkcol = Application.WorksheetFunction.Match(lookupkey,
rng, 0)
rtncol = Application.WorksheetFunction.Match(rtnkey, rng,
0)
Set rng2 = Workbooks("data.xls").Worksheets
("students").Range(Cells(1, lkcol), Cells(65535, lkcol))
rtnrow = Application.WorksheetFunction.Match(lookupval,
rng2, 0)
Sinfo = Workbooks("data.xls").Worksheets("students").Cells
(rtnrow, rtncol)
End Function