Excel VBA基础教程——循环

Sub 过程名()

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 条评论
登录 后参与评论

扫码关注云+社区