I have two workbooks in Excel 2007, A and B.
Within A I have a function that needs to get certain values from workbook B. I find no way to do this within a function (within a normal sub is no problem, but I need a function – which actually is more complicated than just getting the cell(1,1) )
in A:
function getDataFromB(sheetName,row,col)
x = Application.run ("E:\B.xlsm!getData",sheetName,row,col)
getDataFromB = x
end getDataFromB
In B
function getData(sheetName,row,col)
x=sheets(sheetName).cells(row,col)
getData = x
end getData
Whenever getData within B is called it looks for sheetName in workbook A – not B. And writing
x = workbooks("E:\B.xlsm").sheets(sheetName).cells(row,col)
does not work
How would I solve this?
TIRED AND TESTED
Change
to
Also in File B Change the code to
You need to add “End Function” as I have done above.