Excel VBA----之do loop循环
1、1、do.....Loop:循环语句,直至满足条件后退出。
2、2、在VBE中编写代码:
Sub doLoop()
Dim a%
Do
a = a + 1
If a > 10 Then
Debug.Print ("a已经超过10了,该停止了!")
Exit Do
End If
Loop
End Sub
功能为:当a超过10时,将退出该程序。
3、3、运行该代码,运行11次时,将输出 a已经超过10了,该停止了!
4、接下来,将对Do....Loop 进行复杂案例说明:
5、1、Excel界面的初始数据为:
6、2、在VBE中编写如下代码:
Sub judge()
Dim rs%
rs = 1
Do
rs = rs + 1
If rs > 10 Then
Exit Do
Else
If Cells(rs, 2) > 90 Then
Cells(rs, 3) = "是"
End If
End If
Loop
End Sub
7、3、在Excel界面中指定宏,并运行代码,得到如下结果。
即:当分数超过90时,将在第三列中得到 是否为优秀的结果。
8、综上所述,本文说明了Do....Loop的使用说明,并结合Excel进行案例场景使用。
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:25
阅读量:37
阅读量:68
阅读量:53
阅读量:31