i copied and pasted it but it wouldn't work
Ran perfectly for me when I tested it in your sample workbook.
Did you attempt to alter the code? Did you put it in the correct sheet module? Did you copy and paste the function code to a standard module?