Jonmo1
MrExcel MVP
- Joined
- Oct 12, 2006
- Messages
- 44,061
This is just a general question about VBA practices, no immediate impact.
Is the only purpose for the line "Option Explicit" at the top of a module to require variables types to be declared within that module? Is there some other purpose for that line that I'm missing?
While I certainly understand that many times it is necessary to declare the variable type, you can certainly agree that it is not always necessary.
Like a simple loop
For i = 1 to 100
If you don't use option explicit and do not declare the type, VBA assumes you mean x is a number (int, long).
or if you say x = "dog" - VBA assumes the variable type is string
A silly comparison would be...
I almost always like ICE in my Glass of Water. But sometimes I don't need or want the Ice. So it would be pretty silly to program my refrigerator to refuse to put water in the glass if I had not put ICE in it first.
Thanks
edited -
And don't come back with "Get your water from the sink then". If that's your response, you missed my point altogether.

Is the only purpose for the line "Option Explicit" at the top of a module to require variables types to be declared within that module? Is there some other purpose for that line that I'm missing?
While I certainly understand that many times it is necessary to declare the variable type, you can certainly agree that it is not always necessary.
Like a simple loop
For i = 1 to 100
If you don't use option explicit and do not declare the type, VBA assumes you mean x is a number (int, long).
or if you say x = "dog" - VBA assumes the variable type is string
A silly comparison would be...
I almost always like ICE in my Glass of Water. But sometimes I don't need or want the Ice. So it would be pretty silly to program my refrigerator to refuse to put water in the glass if I had not put ICE in it first.
Thanks
edited -
And don't come back with "Get your water from the sink then". If that's your response, you missed my point altogether.
