excel vba程序流程控制——For—Next 循环语句
Sub mysum()
Dim Lsum As Long, i As Long
For i = 1 To 1000
Lsum = Lsum + i
Next
MsgBox "1到1000的自然数和为:" & Lsum
End Sub
Sub 求1到10000之间偶数和()
Dim I&, J&
For I = 0 To 10000 Step 2
J = J + I
Next
MsgBox "1到10000之间偶数和为" & J
End Sub
Sub 求1到10000之间偶数和2()
Dim I&, J&
For I = 10000 To 1 Step -2
J = J + I
Next
MsgBox "1到10000之间偶数和为" & J
End Sub
Sub 求1到10000之间奇数和()
Dim I&, J&
For I = 1 To 10000 Step 2
J = J + I
Next
MsgBox "1到10000之间奇数和为" & J
End Sub
Sub 求1到10000之间奇数和2()
Dim I&, J&
For I = 9999To 1 Step -2
J = J + I
Next
MsgBox "1到10000之间奇数和为" & J
End Sub
Sub 求1到10000之间能被5整除的数之和()
Dim I&, J&
For I = 0 To 10000 Step 5
J = J + I
Next
MsgBox "1到10000之间能被5整除的数之和为" & J
End Sub
Sub 求1到10000之间能被5整除的数之和2()
Dim I&, J&
For I = 10000 To 1 Step -5
J = J + I
Next
MsgBox "1到10000之间能被5整除的数之和为" & J
End Sub
关注咕吧课堂 excel vba资料随意找