Only comments may appear after End Sub, End Function, or End Property

This page is specific to the Visual Basic for Applications (VBA) Language Reference for Office 2010.

Only comments, directives, and declarations are permitted outside procedures. This error has the following cause and solution:

  • You placed executable code outside a procedure. Any nondeclarative lines outside a procedure must begin with a comment delimiter ('). Declarative statements must appear before the first procedure declaration. Comments are ignored when the code executes.

For additional information, select the item in question and press F1 (in Windows) or HELP (on the Macintosh).