Excel VBA基础教程——循环

2018-06-26 17:23:28 浏览数 (1)

Sub 过程名()

代码语言:javascript复制
i = 1
s = 0 '初始值为0可略

While i <= 100
    s = s   i
    i = i   1
Wend

Do While i <= 100
    s = s   i
    i = i   1
Loop

Do '第一次无条件执行
    s = s   i
    i = i   1
Loop While i <= 100

Do
    s = s   i
    i = i   1
Loop Until i > 100

Do
    s = s   i
    i = i   1
    If i > 100 Then Exit Do
Loop

For i = 1 To 100
    s = s   i
Next

For Each sh In Sheets
    sh.[A1] = sh.Name
Next

End Sub

0 人点赞