What does Option Explicit mean and do?

Cosmos75

Active Member
Joined
Feb 28, 2002
Messages
359
Can anyone help explain what does Option Explicit means and what does it do in a macro? (kinda redundant, I know, since the topic is self-explanatory)
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
From the VBA help files, explains it quite neatly really and should always be your first port of call: -

Used at module level to force explicit declaration of all variables in that module.

Syntax

Option Explicit

Remarks

If used, the Option Explicit statement must appear in a module before any procedures.

When Option Explicit appears in a module, you must explicitly declare all variables using the Dim, Private, Public, ReDim, or Static statements. If you attempt to use an undeclared variable name, an error occurs at compile time.

If you don't use the Option Explicit statement, all undeclared variables are of Variant type unless the default type is otherwise specified with a Deftype statement.

Note Use Option Explicit to avoid incorrectly typing the name of an existing variable or to avoid confusion in code where the scope of the variable is not clear.
 
Upvote 0
Sorry about that. But my computer at work doesn't have the VBA help files installed. And I am not sure if the IT people would want me to install it.

Is there an online source where I can look all of this up?
 
Upvote 0
It forces variable definitions. This helps when you use variables to hold and insert or exchange data or controls with in code. This form allows for a clear scope of use when variable usage is complicated or could become unclear. Its use also helps keep frequently used variables from being miss-typed. Helps keep variables from being assigned a variant type if not defined with a Def statement. The down side is it can only be used in a true module.

The skinny on it is: It forces explicit variable declaration. Hope this helps. JSW
 
Upvote 0
Oh, no, I wasn't having a go at you :). It was meant just as a tip as the help files are very useful. I don't see why IT wouldn't let you have them, they should be there after a standard Excel/ Office install anyway.
 
Upvote 0
It would probably be easier to go and ask your IT people to install it or install it yourself if your system does that "install on first use" thingy.

If they say "no" demand a reason. If the reason is insufficient give them so many lefts that they'll be begging for a right.

Verbal abuse doesn't seem to have much effect on IT people (ours have built up a tolerance to it), stick to the violence.

HTH
 
Upvote 0

Forum statistics

Threads
1,213,531
Messages
6,114,167
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top