How do I fix runtime error 9 subscript out of range?
How to fix runtime error 9: subscript out of range
- Add a default printer. Connect a printer to your computer, plug in the power cord, and turn it on. Go to “Start” > “Control Panel” > “Printers and Faxes”.
- Install updates. Go to “Start” > “Control Panel”.
- Scan the Registry. Download and install a registry cleaner.
Table of Contents
What to do if the subscript is out of range?
For example, if you refer to the sheet that is not in the workbook, we get runtime error 9: “Subscript out of range”. Clicking the Finish button will terminate the subprocedure, clicking debug will take you to the line of code where you encountered an error, and help will take you to the page on the Microsoft website.
Why is subscript out of range in VBA?
The VBA Subscript out of range error occurs because the object we are trying to access does not exist. This is some kind of error in VBA coding, and this is a “Runtime Error 9”. It is important to understand the concepts to write efficient code, and it is even more important to understand the error of your VBA code to efficiently debug the code.
What does out of range mean in VBA?
tl; dr: subscript out of range error usually means that VBA can’t find the Excel object you’re trying to reference. Correct the reference name and your code should work. Often times, the VBA Subscript Out of Range error will be one of the first errors you encounter. This can happen with recorded macros or self-written VBA.
What causes the “out of range” error in Visual Basic?
For example, the following code causes this error: Dim MyArray() As Integer MyArray(8) = 234 ‘ Causes error 9. Visual Basic does not implicitly size unspecified array ranges as 0 – 10. Instead, you should use Dimor ReDim to explicitly specify the number of elements in an array. You referenced a nonexistent collection member.