Local for loop variable and other basic questions

epslugger

New Member
Joined
Nov 17, 2012
Messages
3
Hi,

I'm coding in excel 2010 and I was wondering if there is a way to create a variable that is local to a for loop. The equivalent code in c++ would be:

for(int i=0; i<10; i++).

I have tried the following and I get the error "Compile Error Expected: ="

For i as Integer = 0 To 10 Step 1
Next i

Thanks
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
You can't do that in VBA.

Just out of curiousity why would you want to?
 
Upvote 0
Currently I have many for loops with variable like i1, i2, i3, i4, i5, j1, j2, j3.... If i could make them local to the for loop they are used in, then I could just have i and j be used over an over again. This would eliminate many lines of my code devoted to declaring these variables.
 
Upvote 0
You can use i and j over and over again, you don't need to use a different variable for each loop.
 
Upvote 0

Forum statistics

Threads
1,215,473
Messages
6,125,018
Members
449,203
Latest member
tungnmqn90

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