首页 > 代码库 > VBA基础——循环语句
VBA基础——循环语句
VBA基础之循环语句
Sub s1() Dim rg As Range For Each rg In Range("a1:b7,d5:e9") If rg = "" Then rg = 0 End If Next rg End Sub Sub s2() Dim x As Integer Do x = x + 1 If Cells(x + 1, 1) <> Cells(x, 1) + 1 Then Cells(x, 2) = "断点" Exit Do End If Loop Until x = 14 End Sub
VBA各语句对比
Sub t1() Range("d2") = Range("b2") * Range("c2") Range("d3") = Range("b3") * Range("c3") Range("d4") = Range("b4") * Range("c4") Range("d5") = Range("b5") * Range("c5") Range("d6") = Range("b6") * Range("c6") End Sub Sub t2() Dim x As Integer For x = 10000 To 2 Step -3 Range("d" & x) = Range("b" & x) * Range("c" & x) Next x End Sub Sub t3() Dim rg As Range For Each rg In Range("d2:d18") rg = rg.Offset(0, -1) * rg.Offset(0, -2) Next rg End Sub Sub t4() Dim x As Integer x = 1 Do x = x + 1 Cells(x, 4) = Cells(x, 2) * Cells(x, 3) Loop Until x = 18 End Sub Sub t5() x = 1 Do While x < 18 x = x + 1 Cells(x, 4) = Cells(x, 2) * Cells(x, 3) Loop End Sub
VBA基础循环语句对比
VBA基础——循环语句
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。