2

我需要为此单元格复制/粘贴的起始位置创建一个变量,以便可以将其用作其他数据的参考点。那可能吗?我不确定语法。

wbkCS.Worksheets("Cut Sheet").Range("S4:S2000").Copy

With wbkVer.Worksheets("Cutsheets")
   .Range("A" & .Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
End With
4

2 回答 2

9

这是将这些范围保存为Range对象的语法。

dim firstRange as Range, secondRange as Range

set firstRange = wbkCS.Worksheets("Cut Sheet").Range("S4:S2000")

firstRange.copy

With wbkVer.Worksheets("Cutsheets")
    set secondRange = .Range("A" & .Rows.Count).End(xlUp).Offset(1)
    secondRange.PasteSpecial xlPasteValues
End With

如果您想要其中一个范围的第一个单元格,它将是这样的:

firstRange.Cells(1,1)

于 2012-12-31T20:51:20.763 回答
2

您已经有了答案,但最好的办法是完全避免使用剪贴板,如下所示:

Sub WithoutClipboard()

'define the two ranges variables
Dim firstRange As Range
Dim secondRange As Range

'set the range variables to specific ranges
Set firstRange = wbkCS.Worksheets("Cut Sheet").Range("S4:S2000")
With wbkVer.Worksheets("Cutsheets")
    Set secondRange = .Range("A" & .Rows.Count).End(xlUp).Offset(1)
End With

'resize the second range so it exactly the same size as the first range
With firstRange
      Set secondRange = secondRange.Resize(.Rows.Count, .Columns.Count)
End With

'move the data without having to use copy/paste
secondRange.Value = firstRange.Value

End Sub
于 2013-01-01T13:48:22.433 回答