码迷,mamicode.com
首页 > 编程语言 > 详细

VBA基础——循环语句

时间:2016-12-07 20:40:36      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:ext   amp   off   cell   语句   基础   str   while   bsp   

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基础——循环语句

标签:ext   amp   off   cell   语句   基础   str   while   bsp   

原文地址:http://www.cnblogs.com/newcode/p/6142462.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!