我想复制工作表3的单元格区域(C1:Z1000)并将它们粘贴到工作表1的第一个空列(在第1行中)。在最后的线下块代码:source.Range个( “C:Z1000”)。复制destination.Cells(1,emptyColumn)在excel vba的第一个空列中复制粘贴范围
Sub CopyRange()
Dim source As Worksheet
Dim destination As Worksheet
Dim emptyColumn As Long
Set source = Sheets("Sheet3")
Set destination = Sheets("Sheet1")
'find empty Column (actually cell in Row 1)'
emptyColumn = destination.Cells(1, destination.Columns.Count).End(xlUp).Column
If emptyColumn > 1 Then
emptyColumn = emptyColumn + 1
End If
source.Range("C1:Z1000").Copy destination.Cells(1, emptyColumn)
End Sub
您的代码是不合逻辑的。您检查sheet3的LAST列是否为空,如果不是,则取下NEXT列。当然哪个永远不会存在。 –