What is it you expect the function to return? Assuming the Sub in your worksheet works the only thing you need to do to switch it to a function is to replace "sub" with "function" :P