For Loop: Sub Example1
For Loop: Sub Example1
Sub Example1()
For i = 1 To 4 1
2
5 3
Cells(i, i) = I
4
Next i
Range("A3")= i
End Sub
Sub Example2()
1 11
For i = 10 To 1 Step -2
3
Cells(i, 1) = i
5
Next i
7
Range("C1")= i
9
End Sub
Sub Example3()
15
Sum=0
For i = 1 To 5
Sum = Sum + i
Next i
Range("A1")= Sum
End Sub
Exercise: Use for loop solve the following questions and
place the result in one of the cells
1) Find the summation of the even numbers between 2
and 100.
(Sol= 2550)
2) Find the value of W from the Equation
𝑊 = 1 × 3 × 5 × 7 × 9 × 11 × 13
(Sol= 135135)
3) Find The value of W from the Equation
1 1 1 1 1 1 1
𝑆 =1+ + + + + + +
2 4 8 16 32 64 128
(Sol= 1.99)
1) Find the summation of the even numbers between 2 and 100.
(Sol= 2550)
Sub Ex1()
Sum=0
For i = 2 To 100 Step 2
Sum = Sum + i
Next i
Range("A1") = Sum
End Sub
S = S + (1 / D) S=S+D S=S+1/2^i
D=D*2 D=D/2
Next i
Next I Next i
Range("A1") = S
Range("A1") = S Range("A1") = S
End Sub End Sub End Sub