So I tried running Alf's code again and somehow it ended up working this time and has been working every time since! Thanks so much anyway!

One other question. What edit would you make to get the macro to only run on visible cells?