我想将列的数据(例如:A2:A10)复制到C2:C10。但是,如果 C2:C10 已经有数据,我希望它将数据复制到右侧的下一列。在此示例中为 D2:D10。
我将如何实现这一目标?
先谢谢了
Option Explicit
Sub CopyCol()
Dim rngFrom As Range, rngTo As Range
With ActiveSheet
Set rngFrom = .Range("A2:A10")
Set rngTo = rngFrom.Offset(, 2)
Do While WorksheetFunction.CountA(rngTo) > 0
Set rngTo = rngTo.Offset(, 1)
Loop
rngFrom.Copy rngTo
End With
End Sub