Excel 使用R1C1时避免在两张纸之间复制和粘贴-我是否必须停止使用;用sheetname“吗;?

Excel 使用R1C1时避免在两张纸之间复制和粘贴-我是否必须停止使用;用sheetname“吗;?,excel,vba,Excel,Vba,我一直在读到,最好避免在VBA中使用复制和粘贴,因为它可以更快地使一个范围等于另一个范围 但是,如果我想使用R1C1引用将数据从一张表移动到另一张表,这似乎意味着代码必须更难阅读和理解 如果我通常使用: With sheetOne .Range(.Cells(row1, col1), .Cells(row2, col2)).Copy End With With sheetTwo .Range(.Cells(row3, col3).address).PasteSpecial xl

我一直在读到,最好避免在VBA中使用复制和粘贴,因为它可以更快地使一个范围等于另一个范围

但是,如果我想使用R1C1引用将数据从一张表移动到另一张表,这似乎意味着代码必须更难阅读和理解

如果我通常使用:

With sheetOne
    .Range(.Cells(row1, col1), .Cells(row2, col2)).Copy
End With

With sheetTwo
    .Range(.Cells(row3, col3).address).PasteSpecial xlPasteValues
End With

然后,我可以看到不使用“复制和粘贴”的唯一方法是多次重复工作表名称,因为我不能将
一起使用:

sheetTwo.Range(sheetTwo.Cells(row3, col3), sheetTwo.Cells(row4, col4)) = _
sheetOne.Range(sheetOne.Cells(row1, col1), sheetOne.Cells(row2, col2))

我更喜欢将
一起使用,因为重复这样的工作表名称感觉像是浪费,但是如果我要停止使用复制和粘贴,我是否必须按照上面第二段代码的路线进行操作?

实际上不是这样

sheetTwo.Range(sheetTwo.Cells(row3, col3), sheetTwo.Cells(row4, col4)) = _
sheetOne.Range(sheetOne.Cells(row1, col1), sheetOne.Cells(row2, col2))
你可以这样做

With sheetOne
    Dim SrcRange As Range
    Set SrcRange = .Range(.Cells(row1, col1), .Cells(row2, col2))
End With

With sheetTwo
    Dim DestRange As Range
    Set DestRange = .Range(.Cells(row3, col3), .Cells(row4, col4))
End With

DestRange.Value = SrcRange.Value


请注意,
.Range(.Cells(row3,col3).address).PasteSpecial
.Cells(row3,col3).PasteSpecial
是的,我想我知道这一点,但出于某种原因,我一直用更长的方法来做。谢谢
With sheetOne
    Dim SrcRange As Range
    Set SrcRange = .Range(.Cells(row1, col1), .Cells(row2, col2))
End With

With sheetTwo
    .Range(.Cells(row3, col3), .Cells(row4, col4)).Value = SrcRange.Value
End With