Excel VBA 循环“我中毒了~”
来源:http://mcdelfino.blog.51cto.com/2058744/691131
Dim Runtime As Date Sub RunTimer() Runtime = Now() + TimeValue("00:00:01") Application.OnTime Runtime, "my_Procedure" End Sub Sub my_Procedure() Static count As Integer count = count + 1 For i = 1 To 10 For j = 1 To 20 Cells(i + (count - 1) * 10, j) = "我中毒了~~~~" Cells(i + (count - 1) * 10, j).Font.Color = vbRed Cells(i + (count - 1) * 10, j).Font.Size = 10 Next Next If count = 10 Then Exit Sub End If RunTimer End Sub
就是一个在单元格中的循环,按时间来循环,每过1秒钟进行一个循环~
为了不让其无限循环下去,设置了循环10次即退出~
吃饭倒计时:
Dim Runtime As Date Sub RunTimer() Runtime = Now() + TimeValue("00:00:01") Application.OnTime Runtime, "my_Procedure" End Sub Sub my_Procedure() Cells(1, 2) = Format(Now(), "h:mm:ss") Cells(2, 2) = "18:00:00" Cells(3, 2) = Format(Cells(2, 2) - Cells(1, 2), "h:mm:ss") Cells(4, 2) = Format(TimeValue("18:00:00") - TimeValue(Now()), "h:mm:ss") RunTimer End Sub