|
本帖最后由 sunjing-zxl 于 2012-3-17 21:28 编辑
- Sub 练习1()
- Dim i As Long
- With Sheets("练习")
- For i = 7 To 15
- .Cells(i, 1) = .Cells(i, 1).Row
- Next i
- End With
- End Sub
- Sub 练习2()
- Dim i As Long
- For i = 1 To Sheets.Count
- Sheets(i).Range("M2") = "EP"
- Next i
- End Sub
- Sub 练习3()
- Dim x As Long, y As Long, z As Long
- '方法1
- x = 1: y = 1: z = 0
- Do While z < 10000
- z = x + y
- x = y: y = z
- Loop
- MsgBox "小于1万,且最接近1万的数是:" & x, , "方法1"
- '方法2
- x = 1: y = 1: z = 0
- Do
- z = x + y
- x = y: y = z
- Loop While x + y < 10000
- MsgBox "小于1万,且最接近1万的数是:" & z, , "方法2"
- End Sub
- Sub 练习4()
- Dim rng As Range, rng1 As Range, T As Double
- Dim i As Byte, Ysa As Byte, Ysb As Byte
- Sheets("循环可以做什么").Select
- With Sheets("循环可以做什么")
- Do
- Ysa = Int(Rnd * 55 + 1)
- Loop Until Ysa <> [AW16].Interior.ColorIndex
- Do
- Ysb = Int(Rnd * 55 + 1)
- Loop Until Ysb <> [AW17].Interior.ColorIndex And Ysb <> Ysa
- Set rng = .Range("AV9:AX23")
- For i = 1 To 6
- Set rng = Union(rng, .Range(.Cells(15 - i, 41 + i), .Cells(17 + i, 41 + i)), .Range(.Cells(15 - i, 57 - i), .Cells(17 + i, 57 - i)))
- Next i
- For Each rng1 In rng
- T = Timer
- Do While Timer < T + 0.005
- DoEvents
- Loop
- If rng1.Address = "$AW$16" Then
- rng1.Interior.ColorIndex = Ysa
- Else
- rng1.Interior.ColorIndex = Ysb
- End If
- Next
- End With
- End Sub
- Sub 返回()
- Sheets("练习").Select
- End Sub
复制代码 附件:
循环在VBA中的运用练习题-sunjing-zxl.rar
(83.53 KB, 下载次数: 3)
|
评分
-
参与人数 1 | +17 |
金币 +17 |
收起
理由
|
FF7
| + 17 |
+ 17 |
练习4代码效果很漂亮,很用心的作品。加5分. |
查看全部评分
|