Error 91 — “Object variable or With block variable not set” — means your code tried to use an object variable that currently points at nothing. The variable exists; the object doesn't. This is one of the most honest errors VBA gives you: find which variable is empty, work out why, and the fix follows. No downloads, no repair tools.
In VBA, object variables (a Worksheet, a Range, a workbook, any class object) don't hold the object itself — they hold a reference to it. Until you assign that reference with the Set keyword, the variable's value is the special state Nothing. The moment code tries to read a property or call a method on a variable that is Nothing — ws.Name, rng.Value, anything — VBA stops with error 91. The same thing happens inside a With block whose object is Nothing.
? ws Is Nothing (using your variable's name) and press Enter. True confirms it — that variable was never successfully assigned, or was set back to Nothing.Cause 1The Set is missing.
The classic. Object variables must be assigned with Set. Leave it out and the assignment either fails or assigns the object's default value instead of the object — and the variable stays Nothing.
Dim ws As Worksheet
ws = ThisWorkbook.Worksheets("Report") ' wrong — no Set
ws.Range("A1").Value = 5 ' error 91 here
Fix: add the keyword:
Set ws = ThisWorkbook.Worksheets("Report")
Rule of thumb: if the thing on the right is an object — a sheet, a range, a workbook, a dictionary, anything you created with New — the assignment needs Set.
Cause 2A lookup returned Nothing — most often Range.Find.
Find does not raise an error when the value isn't there; it returns Nothing, by design. Code that uses the result without checking it works perfectly right up until the first search that finds nothing — then error 91, usually reported by a user whose data changed.
Dim found As Range
Set found = ws.Range("A:A").Find("Invoice 1042")
found.Offset(0, 1).Value = "Paid" ' error 91 when the invoice isn't in column A
Fix: test the result before using it, every time:
If Not found Is Nothing Then
found.Offset(0, 1).Value = "Paid"
Else
MsgBox "Invoice 1042 not found"
End If
The same pattern applies to anything that can hand back Nothing: dictionary lookups you've built yourself, functions that return an object, and Collection wrappers.
Cause 3The variable was set — then set to Nothing, or fell out of scope.
A well-meaning Set ws = Nothing at the end of one routine, a shared variable cleared by another macro, or the assignment living in a different procedure than the use: a variable declared inside Sub A does not exist in Sub B. When execution reaches the use, the (new, empty) variable is Nothing.
Fix: trace the variable's whole life: where it's declared, where it's Set, anywhere it's Set to Nothing, and whether the code path that errors actually passes through the assignment. If two routines need the same object, pass it as a parameter instead of relying on a shared variable being filled in first.
Cause 4The With block's object is Nothing.
The error message names this case directly: With someObject where someObject was never assigned raises 91 on the first line inside the block — which is misleading, because the lines inside look innocent. They are; the With line itself is the problem, for one of the reasons above.
Fix: check the object on the With line in the Immediate window (? someObject Is Nothing) and fix its assignment first. Don't debug the block's contents — they never got a chance to run.
Cause 5An object from another application or library failed to be created.
Code that creates objects from outside Excel — CreateObject("Scripting.FileSystemObject"), an Outlook or Word instance, a database connection object — can end up with Nothing if the creation failed, the library isn't available, or the reference broke. The 91 then appears at the first use, not at the creation line, which makes it look like Cause 1.
Fix: test immediately after creating: If fso Is Nothing Then handle it there, where the real problem is visible. In the VBA editor, also check Tools → References for any entry marked MISSING — a broken reference can stop object creation cold.
Debug.Print variableName Is Nothing. Run the macro and read the Immediate window: the first True is where the chain breaks.If that didn't run, an On Error Resume Next that silently swallowed the real error on the Set line, or an early Exit Sub all leave the variable Nothing while the code looks complete. Temporarily comment out On Error Resume Next and run again — the original error often names itself.End. A bare End statement anywhere in the run resets all variables to Nothing instantly. If 91 appears after a dialog or a cancel button, search the project for End used where Exit Sub was meant.