How to Fix Excel VBA Runtime Error 9 When Making Cells Blink
Question details
The user needs to fix a VBA script that triggers an error when trying to create a blinking effect for specific cells.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Using the Application.OnTime method in VBA to make cells in column M blink red and white when their value is 'YES'.
- Observed behavior
- The macro execution fails and throws 'Runtime Error 9: Subscript out of range', causing the blinking effect to stop working.
Before modifying your VBA script, verify the exact name of your worksheet tab and ensure your workbook is saved as a Macro-Enabled Workbook (.xlsm).
Fully Qualify Worksheet and Workbook References
Fix Runtime Error 9 by explicitly defining the target workbook and worksheet instead of relying on the ActiveSheet.
Runtime Error 9 ('Subscript out of range') most commonly occurs when VBA cannot find the specified object. When running timer-based macros like Application.OnTime, the active worksheet might change while the user navigates, causing the code to fail if references are not fully qualified.
Press 'Alt + F11' on your keyboard to open the Visual Basic for Applications (VBA) editor, then locate the module containing your blinking cell macro.
Look for range references that stand alone, such as 'Range("M3:M20")', or index-based worksheet references like 'Worksheets(1)'.
Update the code to explicitly call the workbook and worksheet name. For example, change it to 'ThisWorkbook.Worksheets("Sheet1").Range("M3:M20")'. Replace 'Sheet1' with the actual name of your worksheet.
Save your code and trigger the macro again to verify that the blinking effect runs on the specified YES values without throwing Error 9.

Properly Cancel the Scheduled Application.OnTime Procedure
Prevent recursive errors and performance issues by ensuring your scheduled macro is correctly declared and cancelled when the workbook closes.
Write and Debug VBA Macros Seamlessly in WPS Office
WPS Office provides robust built-in support for VBA macros, allowing you to easily edit, debug, and run advanced scripts like Application.OnTime blinking effects.
- 1. Install WPS Office: Download and install WPS Office, then open your macro-enabled spreadsheet file.
- 2. Access the Developer Tools: Navigate to the 'Developer' tab on the top ribbon and click on 'Visual Basic' to launch the VBA Editor.
- 3. Edit Your Macro: Locate your Application.OnTime module and update your worksheet references to be fully qualified.
- 4. Execute the Code: Run the updated script directly within the editor to instantly test your blinking cells in column M.

Frequently Asked Questions
What does VBA Runtime Error 9 mean?
Runtime Error 9 stands for 'Subscript out of range.' It means that VBA is trying to access an element in a collection (like a Worksheet, Workbook, or Array) that does not exist. This is usually caused by misspelled sheet names or referencing a workbook that is closed.
Why does Application.OnTime cause my workbook to reopen?
If an Application.OnTime schedule is not explicitly cancelled before closing the workbook, the Excel application remembers the timer. When the scheduled time arrives, Excel will automatically reopen the file to execute the macro. Always cancel the timer using the Workbook_BeforeClose event.
Can blinking cells slow down my Excel workbook?
Yes. Continuous looping macros like a 1-second Application.OnTime timer consume processing power. This can interrupt user interface interactions, clear your clipboard unexpectedly, and slow down your overall workflow.
How do I forcibly stop a looping VBA macro?
If your blinking macro gets stuck in an infinite loop or you cannot click anything, press 'Ctrl + Break' (or 'Ctrl + Pause') on your keyboard. This interrupts the code execution and allows you to enter debug mode or end the process.




