我正在尝试制作一个循环,将具有特定间隔的特定选择复制到新范围或新范围。
这是我的代码:
Sub test()
Dim i As Long
Dim c As Integer
c = 0
For i = 1 To 119 Step 3
c = c + i + 120
Range(Cells(i, 1), Cells(i, 4)).Copy Range("A(c)")
Next i
End Sub
但它不起作用。有人能帮帮我吗?
感谢!!!!!!
答案 0 :(得分:1)
非常感谢你。我用这种方式解决了它,使其更加紧凑:
Sub test()
Dim i As Long
Dim c As Integer
Dim c2 As Integer
c = 0
c2 = 0
For i = 1 To 119 Step 3
c2 = c2 + 1
c = c2 + 120
Range(Cells(i, 1), Cells(i, 4)).Copy Cells(c, 1)
Next i
End Sub
答案 1 :(得分:1)
如果您只想选择要复制的范围而不实际复制任何内容:
Sub test()
Dim i As Long
Dim rngCopy As Range
For i = 1 To 119 Step 3
If rngCopy Is Nothing Then
Set rngCopy = Range(Cells(i, 1), Cells(i, 4))
Else
Set rngCopy = Application.Union(rngCopy, _
Range(Cells(i, 1), Cells(i, 4)) )
End If
Next i
rngCopy.Select
End Sub