|
Sub dd()
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
我的问题是: If x = 2 Then Set rg = Cells(x, 1) 当x=2, rg=A2;
Set rg = Union(rg, Cells(x, 1)) 由于上一句中rg=a2, 这句话中是不是同是存在两个A2(union(range(“A2”), range(“A2”))?
如果不是的话,请详解一下,当x=2和x=4时, Set rg = Union(rg, Cells(x, 1)) 包含的单元格?
- Sub dd()
- Dim rg As Range, x As Integer
- For x = 2 To 10 Step 2
- If x = 2 Then Set rg = Cells(x, 1)
- Debug.Print "union前:" & rg.Address
- Set rg = Union(rg, Cells(x, 1))
- Debug.Print "union后:" & rg.Address
- Next x
- rg.Select
- End Sub
复制代码看下立即窗口的内容。
|
|