Completed script to export to Excel