Must be first statement on the line
Not all keywords can appear at the beginning of a line of code. This error has the following causes and solutions:
You preceded a Sub, Function, or Property statement with another statement on the same line. A Sub, Function, or Property statement must always be the first statement on any line in which it appears (unless preceded by the keyword Public, Private, or Static).
You preceded an End If, Else, or ElseIf statement with another statement on the same line. An End If, Else, or ElseIf (only when used in a block If structure) statement must always be the first statement on any line in which it appears.
For additional information, select the item in question and press F1 (in Windows) or HELP (on the Macintosh).
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.