Well wait a minute, let’s look at what the benefits are of the Option Explicit statement before just advising that it be deselected as a default setting.
Option Explicit at the top of a module forces every variable to be declared. There are several reasons why this is a good idea to maintain:
- Spelling errors are identified.
- Your variables can be properly declared by you, not Excel, to have the appropriate memory and system resources assigned to accommodate them. Excel will assign Variant as the variable default type for undeclared variables, not the most efficient use of resources.
- Confusion is avoided if a variable is the same name as a property or method.
Consider the following code:
FindData = InputBox(“Please enter your search term:”)
If FineData = “” Then Exit Sub
Range(“A1”).Value = FindData
Without Option Explicit to guard against spelling errors, cell A1 will never have a value returned into it because of the spelling inconsistency between FindData (line 2) and FineData (line 3). The macro will always exit because FineData will always be thought of as empty.
This kind of mistake might be noticeable with a macro this size, but if it is part of a larger procedure these mistakes are hard to identify. Why take the chance?
I’d recommend keeping Option Explicit as the default statement; it forces better code writing practice, and helps avoid coding errors.