The code worked fine once I removed the last merged cells. Attached is a revised version with a tweak and some tidying up.