When you have a big vba macro / code which needs to run for many minutes, you can change the cursor to the hourglass or waiting cursor (based on your system setting) for the period when the macro is running. Once the macro is completed, the cursor can be restored back to the default cursor.
This is a sample code which shows how you can change the cursor.
Application.Cursor = xlWait
Application.Cursor = xlDefault
- After the dim statements (this sample code doesn’t have any yet), we set Application.Cursor = xlWait at the beginning of the code.
- Then you can include whatever code you need to run. If you need to call multiple subs / procedures, you can do so here or just have the entire code input here.
- Then just before the End Sub statement, you need to reset the cursor back to the default. We do this using the line Application.Cursor = xlDefault
- You can include all the other statements you need like Application.ScreenUpdating = False or Application.DisplayAlerts = False along with the Application.Cursor = xlWait statement. Similarly, you can include Application.ScreenUpdating =True or Application.DisplayAlerts = True along with the Application.Cursor = xlDefault statement.
- To copy this code, press the Alt + F11 keys on the keyboard. This will open the code module. On the left hand side you will see Microsoft Excel Objects. Right click and select Insert and then select Module. Copy the code into the code window on the right.