在对VBA中的数字进行求和时如何计算到10?
答案 0 :(得分:6)
Dim Sum as Integer
Sum = 0
Dim I as Integer
For I = 1 to 10
Sum = Sum + I
Next
修改:有关日后参考,请参阅Visual Basic for Applications (VBA)上的Microsoft MSDN部分
答案 1 :(得分:4)
问题标记为VB6,所以:
Dim Sum As Integer
Dim i As Integer
For i = 1 To 10
Sum = Sum + i
Next i
答案 2 :(得分:0)
这是一种优化的方法。没有速度差异,但最好还是了解一下。
将循环展开至少一个级别
Dim Sum As Long
Dim i As Long
For i = 1 to 10 Step 2
Sum = Sum + i
Sum = Sum + (i + 1)
Next
我希望有所帮助!