I got the function to work by placing it in a module. Prior to that it was in the code for the specific sheet (which doesn't work apparently).