How to Fix Excel VBA Runtime Error 9 When Opening a Hyperlink
Question details
The user is encountering a VBA Runtime Error 9 (Subscript out of range) when trying to execute a macro that opens a hyperlink from an active cell.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Running an Excel macro that relies on the ActiveCell.Hyperlinks(1).Follow method to trigger a hyperlink click automatically.
- Observed behavior
- The macro fails and throws 'Runtime Error 9: Subscript out of range' instead of navigating to the hyperlink destination.
Verify that the cell you are targeting actually contains a standard Excel hyperlink object, as plain blue text or links created using the =HYPERLINK() formula will not be recognized by the VBA Hyperlinks collection.
Add a Conditional Check for Hyperlinks in VBA
Prevent the macro from crashing by checking if the active cell actually contains a hyperlink before calling the Follow method.
Runtime Error 9 occurs because the VBA code attempts to access the first item in the Hyperlinks collection (index 1), but the collection is empty. Wrapping your execution code in a simple conditional statement ensures the method only runs when a valid hyperlink exists.
Press Alt + F11 on your keyboard to open the Visual Basic for Applications editor, then locate the module containing your macro.
Find the line of code that reads: ActiveCell.Hyperlinks(1).Follow
Modify the code to include an If statement: If ActiveCell.Hyperlinks.Count > 0 Then ActiveCell.Hyperlinks(1).Follow End If.
Save your macro, return to your spreadsheet, and test it on both a cell with a hyperlink and a blank cell to confirm the error no longer appears.

Explicitly Define the Target Cell
Avoid using ActiveCell if the macro requires a specific hyperlink, and explicitly declare the exact cell range instead.
Debug and Run VBA Macros Seamlessly in WPS Office
WPS Spreadsheet provides powerful built-in VBA support, allowing you to edit, debug, and run macros just like you do in Microsoft Excel. Fix your script errors easily with its advanced developer tools.
- 1. Download and Install WPS Office: Install the latest version of WPS Office and ensure you have the VBA module enabled.
- 2. Open Your Macro File: Launch WPS Spreadsheet and open your .xlsm or .xlsb file that contains the error.
- 3. Access the VBA Editor: Navigate to the Developer tab on the top ribbon and click on Visual Basic to view your code.
- 4. Apply the Fix: Add the hyperlink count validation to your macro and run it effortlessly without triggering runtime errors.

Frequently Asked Questions
Why does VBA say 'Subscript out of range'?
This error happens when you try to access an element in an array or collection using an index that does not exist. In this specific scenario, the script is trying to access the first hyperlink (index 1) in a cell that has zero hyperlinks.
How can I check if a cell has a hyperlink without using macros?
You can right-click the cell in your spreadsheet. If the context menu displays options like 'Edit Hyperlink' or 'Remove Hyperlink', the cell contains a valid hyperlink object.
Does the HYPERLINK formula count as a hyperlink object in VBA?
No, cells that use the =HYPERLINK() function do not populate the VBA Hyperlinks collection. The ActiveCell.Hyperlinks.Count property will return 0 for these cells, which is a common reason for triggering Error 9.




