How To Fix The Compile Error Expected Expression When Run VBA Command In Excel Immediate Window

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.

  1. Open an Excel workbook, and click the Developer tab —> Visual Basic icon in the Code group.
  2. It will open the VBA editor window. Click the View —> Immediate Window sub-menu item in the VBA window top menu bar.
  3. Then it will open the immediate window on the VBA window bottom right area.
  4. Input the command Range(‘A1’).End(xlToRight) in the immediate window and press the Enter key to execute it.
  5. 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.

  1. Fixing this error is very easy, the error happened because VBA uses the single quotes character ( ‘ ) to add a comment.
  2. So what you need to do is use the double quotes ( ” ” ) to replace the single quotes ” in your Excel VBA command.
    Range("A1").End(xlToRight)
    
  3. Now when you press the Enter key to run the VBA command again, the error will disappear.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.