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
 
Some languages insist on all variables being declared. It forces you to think carefully about what type of data you're handling and it prevents the code from running if you've made a typo.
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I reckon about 5-10% of the questions I see would be eliminated if you couldn't turn Option Explicit off. And I only know of one person who recommends you don't use it versus hundreds who recommend you do.
 
Upvote 0
Guys, thanks for the advice. I was having the problem even with variables such as " i " or " x " in a For Next loop. Do you think you have to declare even those variables? If so let me know. I was refering to that kind of variables.

Thanks for your comments anyway. I'll have them in mind

Regards
 
Upvote 0
Of course you should declare variables like 'i' or 'x', there isn't some special group of variables that don't need to be declared.:)
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,896
Members
452,948
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