Moving the code to a standard module doesn't address the crashing issue -- it's just where the code belongs.

Try adding this line just before the DeleteCustomList line:

            wks.Sort.SortFields.Clear