为单元格位置创buildvariables

我需要为这个单元格复制/粘贴的开始位置创build一个variables,所以我可以用它作为其他数据的参考点。 那可能吗? 我不确定的语法。

wbkCS.Worksheets("Cut Sheet").Range("S4:S2000").Copy With wbkVer.Worksheets("Cutsheets") .Range("A" & .Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues End With 

以下是将这些范围保存为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)

你已经有了答案,但是最好避免使用类似这样的剪贴板:

 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