Dealing with user cancellation of slow macro

This post is a little different from usual.  It concerns VBA macros for MS Excel. Writing macros is quite easy, but writing efficient macros that run in an acceptable time requires a few tweaks.

Commonly known tweaks include turning off screen updating (see the code below for an example of how this works) and then updating the statusbar to show the user progress (also in the code below).

However, what often frustrates me is the inelegant ways in which a user can exit a macro which could take hours to run. I struggled a little to find the approach demonstrated below so I thought it might be useful for others. Continue reading