|
本帖最后由 hwc2ycy 于 2013-1-7 21:44 编辑
既然是要取选单元格,那首先就得先明白如何表示单元格了。
1.表示一个单元格- Sub s()
- Range("a1").Select
- Cells(1, 1).Select
- Range("A" & 1).Select
- Cells(1, "A").Select
- Cells(1).Select
- [a1].Select
- End Sub
复制代码 select方法就是选取(E文字面理解,就能猜出大概意思了)
2 表示相邻单元格区域- Sub d() '选取单元格a1:c5
- MsgBox "Range(""a1:c5"")"
- Range("a1:c5").Interior.ColorIndex = 3
- MsgBox "Range(""A1"", ""C5"")"
- Range("A1", "C5").Interior.ColorIndex = 4
- MsgBox "Range(Cells(1, 1), Cells(5, 3))"
- Range(Cells(1, 1), Cells(5, 3)).Interior.ColorIndex = 5
- MsgBox "Range(""a1:a5"").Offset(0, 1)"
- Range("a1:a5").Offset(0, 3).Interior.ColorIndex = 6
- MsgBox "Range(""a1"").Resize(5, 3)"
- Range("a1").Resize(5, 3).Interior.ColorIndex = 7
- End Sub
复制代码
3 表示不相邻的单元格区域- Sub d1()
- Range("a1,c1:f4,a7").Select
- 'Union(Range("a1"), Range("c1:f4"), Range("a7")).Select
- End Sub
复制代码- Sub dd() 'union示例
- Dim rg As Range, x As Integer
- For x = 2 To 10 Step 2
- If x = 2 Then Set rg = Cells(x, 1)
- Set rg = Union(rg, Cells(x, 1))
- Next x
- rg.Select
- End Sub
复制代码 4.表示行- Sub h()
- 'Rows(1).Select
- 'Rows("3:7").Select
- 'Range("1:2,4:5").Select
- Range("c4:f5").EntireRow.Select
- End Sub
复制代码 5.表示列- Sub L()
- ' Columns(1).Select
- ' Columns("A:B").Select
- ' Range("A:B,D:E").Select
- Range("c4:f5").EntireColumn.Select '选取c4:f5所在的行
- End Sub
复制代码 6.重置坐标下的单元格表示方法- Sub cc()
- Range("b2").Range("a1") = 100
- End Sub
复制代码 7.表示正在选取的单元格区域- Sub d2()
- Selection.Value = 100
- End Sub
复制代码 |
|