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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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