Continue Using Excel While Running a Macro!

The usage of the DoEvents command:

Every VBA programmer knows that Excel will freeze while running a VBA macro. This is not a major issue, but it can be a disturbing situation that lowers the user’s productivity (since they have to wait for the end of the macro). Fortunately, there is a solution to this problem.

If you run the small code below, your Excel will freeze for a few seconds. You will see that you cannot use Excel or even your computer effectively while the macro is running. This will continue until the macro is finished or stopped.

Now we are slightly modifying this code snippet with the DoEvents command. Whenever the macro goes through each loop, the DoEvents command is called. With this modification, you can observe that you can use Excel, click on menus and cells, move around on the ribbon and pages while the macro is running.