The Most Common VBA Runtime Errors – Causes & Solutions
A quick reference for errors you’ll see often—and how to fix them.
9: Subscript out of range
- Wrong sheet/workbook/index.
Set ws = ThisWorkbook.Worksheets("Data") ' not ActiveWorkbook
- Using
Cells(row, "col")with invalid indexes.
91: Object variable not set
- You used a variable like
wsbeforeSet ws = ...succeeded. - Validate existence:
If Evaluate("ISREF('Data'!A1)") Then Set ws = Worksheets("Data")
13: Type mismatch
- Assigning text to numeric or using
Variantunpredictably. - Coerce types or validate with
IsNumeric,CLng,CDbl.
1004: Application-defined or object-defined error
- Invalid range operations, protected sheets, filtered ranges.
- Use
SpecialCells(xlCellTypeVisible)for filtered ranges.
Work faster with the VBA Assistant
Create, explain, and improve your VBA code with examples, comments, and best practices—directly in your workflow.
