Declaring Variables

patupatu

New Member
Joined
Apr 7, 2011
Messages
23
Why do I have to declare all variables in a Macro? All of a sudden now I have to declare all veriables, even i or x as indices in a For - Next loop

I have other macros where I don't have to declare but Global varibles

Thank you in advance
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
If there's "Option Explicit" on the top of the module, then you must declare variables. Also: Tools -> Options -> Require Variable Declaration.
 
Upvote 0
Thank you for your prompt reply; however non of that is taking place.

The thing is that I ran the project at home and I had no problem. Now I am at the office and I am gtting an error: "Compilation error. Cannot find project or Library"
Does this tells you any thing?
Thank you
 
Upvote 0
sounds like you saved it at home, and on a later version of Excel. If so, trying to use it on an earlier version can cause this. I don't know what the fix is, however, other than stripping the code out and reinserting it into a copy of the workbook that has not been saved in the later version.
 
Upvote 0
HHHMMM. Don't think so. I have other projects running at home and at work without problems. ANyways, is there such a thing "Option Implicit" that you can place at the top of th eproject so you don't have to declare simple variables?

Thank you
 
Upvote 0
No, but if you don't have 'Option Explicit', then it defaults to allowing you to use variables without declaring them (not good practice, though)
 
Upvote 0
If you are getting a project error, check Tools-References and look for a checked item that starts with 'MISSING:'
 
Upvote 0
No, but if you don't have 'Option Explicit', then it defaults to allowing you to use variables without declaring them (not good practice, though)
I would endorse this comment wholeheartedly.
 
Upvote 0
Methinks requiring variable declaration should be the default, and the alternative would require you to use

Code:
Option Bad Practice
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,874
Members
452,949
Latest member
Dupuhini

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