I currently use a UDF to look up values from a table in my personal workbook and it works just as I need it to. However I was hoping to be able to share this UDF with other people I work with. I have mine saved in a .xlam and loaded as an addin. I am looking for a solution where I could reference one workbook shared on a shared server. The reason for this is the table needs updated one to several times per month and it would be easier if one person was updating the master table opposed to everyone updating their personal workbooks.
From what I have read you cannot use a UDF to reference a workbook which is not already open. I was hoping someone could let me know if there is another way to achieve what I am hoping to do.
Function region(profit_center)
Dim pc_range As Range
Set pc_range = Workbooks("PERSONAL.xlsb").Sheets("Profit Center").Range("J1:K800")
region = Application.WorksheetFunction.VLookup(profit_center, pc_range, 2, False)
End Function
After reading some other answers I was under the impression that Index can read closed workbooks from Application.WorksheetFunction.Index but I get a value error when I try this code:
Function region_Index(profit_center)
Dim pc_range1 As Range
Dim pc_range2 As Range
Set pc_range1 = Workbooks("UNC filepath").Sheets("Profit Center").Range("J1:K800")
Set pc_range2 = Workbooks("UNC filepath").Sheets("Profit Center").Range("J1:J800")
region_Index = Application.WorksheetFunction.Index(pc_range1, Application.WorksheetFunction.Match(profit_center,pc_range2,0),2)
End Function
This code works when I am referencing an open workbook but I need it to work when referencing a closed workbook. Again I can use VBA and addins to achieve my goal but I am not sure the best way to do this.