Recently when I run an excel VBA command in excel immediate window, it prompts the error message compile error expected expression. This article will tell you how to fix this error easily.
1. How To Produce The Excel Compile Error Expected Expression.
- Open an excel workbook, and click the Developer tab —> Visual Basic icon in the Code group.
- It will open the VBA editor window. Click the View —> Immediate Window sub-menu item in the VBA window top menu bar.
- Then it will open the immediate window on the VBA window bottom right area.
- Input the command Range(‘A1’).End(xlToRight) in the immediate window and press the Enter key to execute it.
- Then it will pop up a dialog with the error message like below.
Compile error: Expected: expression.
2. How To Fix The Excel Compile Error Expected Expression.
- Fixing this error is very easy, the error happened because VBA uses the single quotes character ( ‘ ) to add a comment.
- So what you need to do is to use the double quotes ( ” ” ) to replace the single quotes ” in your excel VBA command.
- Now when you press the Enter key to run the VBA command again, the error will disappear.