VBA Runtime Error 9

Written by

Mel Jenkins

Reviewed by

Steve Rynearson

Last updated on May 2, 2022

This article will explain the VBA runtime Error 9.

vba 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!

vba error 9 sheet 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.

vba error 9 array


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



VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)

Free Download

Return to VBA Code Examples