Why do you want to put it into a UDF()? Once you have the formula it's easy to just copy & paste it into the cells you want it in.
That said:
VBA functions return a value by putting the value into the function name. IOW when you change the function name, be sure and change all the lines that say "myUDF = " to the new name
Replace the <...> with any # that would indicate something to you.
Example
-99 might mean the workbook couldn't be found
101 might mean the sheet wasn't found
-1 might mean some other error occurred
If there's an error, you don't want myUDF() popping up a message every time it calculates.
I didn't debug this except to make sure there were no syntax errors. I've never used sumif across 2 workbooks. I'm just assuming that the syntax for that formula is correct
From cell J13 you would call it with the formula =myUDF(J13, "FileName")
If FileName will always be the same file, then you could remove the Filename parameter.
To put this into your workbook:
Final note:
You might find it easier to put the sumif into FileName.xlsx, then just point to the proper cell from the current workbook.
Bookmarks