Error 3, “Return without GoSub”, means code reached a Return statement without arriving there through a matching GoSub. Execution fell into the subroutine block by accident, usually by running past the end of the main code, and the Return had nowhere to go back to. This is always a bug in the code's structure, never a problem with the computer or the document.
Exit Sub or Exit Function in between:Sub Report()
GoSub CalcTotals
MsgBox "Done"
Exit Sub ' without this line, flow falls into the block
CalcTotals:
total = total * 2
Return
End Sub
Function. GoSub blocks share all local variables with the caller, which is exactly how stray flow and mystery state get in.return to leave a procedure; in VBA, leaving is Exit Sub or Exit Function, and Return is only legal inside a GoSub block.If the code visibly has an Exit Sub before every labeled block and error 3 still fires, look for a second entry point: an On Error handler that Resumes into the middle of the block, or a GoTo that lands between the label and the Return. Both produce the same error with correct-looking structure.
Is error 3 the same in VB6 and VBA? Yes. The number, the message, and the cause are identical across classic Visual Basic and VBA in Office. A Return with no matching GoSub is invalid in both.
Can error handling cause error 3? Yes. An error handler that uses Resume to jump into a subroutine block, rather than back to the line that failed, enters the block without a GoSub and the Return at the end raises error 3.