VBA Option Explicit
When Option Explicit appears in code, you must explicitly declare all variables by using the Dim or ReDim statements.
If you try to use an undeclared variable name, an error occurs at compile time.
The Option Explicit Off statement allows an implicit declaration of variables.
In the example below, I have not used Option Explicit.
I hope you have noticed in the code given above, that I have written “InrRate” instead of “IntRate” after the Else statement.
But, it doesn’t show any error.
Because we have not been used Option Explicit here, which detects the error in the code show an error when you try to run the code.
Now, let’s learn how to use Option Explicit.
Method 1: You can simply write Option Explicit at the top of the code.
Go to the Tools on the menu bar.
Click on the options button, you can see it in the following window...
Here, tick on the checkbox “Require Variable Declaration”.
You understood how to use Option Explicit, so let’s run the same code after adding Option Explicit.
You will get the following error.