VBA & Macro Problems

How to Fix Excel VBA Runtime Error 9 When Making Cells Blink

Nimra MalikNimra Malik Oct 13, 2026 870 views

Question details

The user needs to fix a VBA script that triggers an error when trying to create a blinking effect for specific cells.

How to Fix Excel VBA Runtime Error 9 When Making Cells Blink
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 you start

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).

Solution 1Recommended

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.

1
Open the VBA Editor

Press 'Alt + F11' on your keyboard to open the Visual Basic for Applications (VBA) editor, then locate the module containing your blinking cell macro.

2
Identify unqualified ranges

Look for range references that stand alone, such as 'Range("M3:M20")', or index-based worksheet references like 'Worksheets(1)'.

3
Apply fully qualified references

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.

4
Run and test

Save your code and trigger the macro again to verify that the blinking effect runs on the specified YES values without throwing Error 9.

Fully Qualify Worksheet and Workbook References
Verify Sheet Tab Names: Ensure there are no hidden leading or trailing spaces in your worksheet tab name, as a mismatch between the VBA code and the tab name will also trigger Error 9.
Seamless VBA Integration

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. 1. Install WPS Office: Download and install WPS Office, then open your macro-enabled spreadsheet file.
  2. 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. 3. Edit Your Macro: Locate your Application.OnTime module and update your worksheet references to be fully qualified.
  4. 4. Execute the Code: Run the updated script directly within the editor to instantly test your blinking cells in column M.
Fully compatible with Microsoft Excel macro formats (.xlsm and .xlsb)Comprehensive built-in VBA editor for troubleshooting Runtime Error 9Lightweight architecture ensures smooth performance even with continuous background macros
microsoft office alternative - wps office

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.