View Full Version : 'For' loop
volabos
06-05-2008, 05:21 AM
I want to create a 'for' loop for 'i' where 'i' will take value in an increament of 12 i.e. 'i' will take values : 1, 13, 25, .... etc in VBA. Can anyone please tell me how to do that?
Regards,
:dunno
grichey
06-05-2008, 05:44 AM
one way to do it w/ a do loop 13 times
option explicit
sub MakeIGoUp()
dim i as integer
i = 1
do
i = i +12
loop until i = 145
End Sub
this should work too
Option Explicit
Sub MakeIGoUp()
Dim i As Integer
i = 1
for i to 145
i = i +12
next i
End Sub
Bob Phillips
06-05-2008, 05:46 AM
For i = 1 To 100 Step 12
'some code
Next i
grichey
06-05-2008, 05:52 AM
For i = 1 To 100 Step 12
'some code
Next i
crafty... I didn't know the step thing existed.
marshybid
06-05-2008, 06:03 AM
Hi there,
For i = 1 To 100 Step 12
'some code
Next i
Would I be right in thinking that if you say Step -12, the loop will count back in negative increments? :dunno
Thanks,
Marshybid
Bob Phillips
06-05-2008, 06:05 AM
Yes, but you have to start at a number greater than the end number.
volabos
06-05-2008, 09:31 AM
thanks Xld for your suggestion.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.