VBA Runtime Error 9
Written by
Reviewed by
This article will explain the VBA runtime Error 9.
This error occurs when you refer to an object or a variable in your code that does not actually exist or when you have declared an array and tried to populate it without defining it’s size.
Object Doesn’t Exist
If you try to select an object that does not exist – this error will occur.
For example, if you rename a sheet to a useful name like “Sales Figures” but then in your code still refer to the sheet by it’s original name!
Error in Array
When you declare an array, and then try to populate the array before you have defined the size of the array, then this error will also occur.
To solve this problem, make sure you have defined the size of the array.
Sub GetFigures()
Dim myArray(1 To 5) As Long
myArray(1) = 10
End Sub