Index Out of Bounds – Causes & Quick Fixes
Runtime Error 9 'Subscript out of Range' occurs when your VBA code accesses an array element, collection, or worksheet with an invalid index. Most common cause: a sheet name that doesn't exist or an array index that's too large.
Discover the features that make our VBA generator the first choice for Excel automation.
Sheets("Sheeet1") instead of Sheets("Sheet1") – a typo in the sheet name is the most common cause of Error 9. Renamed or deleted sheets also trigger this error.
Accessing arr(10) on an array with only 5 elements. Always check UBound() and LBound() before accessing array elements.
Accessing a Dictionary or Collection entry with a key that doesn't exist. Check with .Exists() first.
Our VBA Assistant detects subscript-out-of-range patterns and automatically adds bounds checks and exists validations.
Everything you need to know about our Excel VBA Code Generator.
Deepen your VBA knowledge with these articles
Paste your faulty code and get instant analysis with bounds checks and proper index validations.