我正在尝试复制一系列单元格(A5到C507),从sheet1复制到每行第5列之后的第2页(即A5、E5、I5.)。(很快)点击按钮。但不能在每次单击时更改/增加列。请给我建议。
发布于 2016-03-24 15:38:38
与任务描述相关的Excel代码片段如下:
Sub CopyRange()
Dim I As Integer
Dim maxColumns As Integer
Dim Rng As Range, Rng2 As Range
'set max columns pertinent to your task
maxColumns = 100
'loop through columns w step 4
For I = 0 To maxColumns Step 4
'set source range
With Worksheets(1)
Set Rng = .Range(.Cells(5, I + 1), .Cells(507, I + 3))
End With
'set target range
With Worksheets(2)
Set Rng2 = .Cells(5, I + 1)
End With
' copy source range to the destination
Rng.Copy Destination:=Rng2
Next I
End Sub您可以修改每个任务的上限(本例中为maxColumns = 100列)。
希望这能帮上忙。
https://stackoverflow.com/questions/36203521
复制相似问题