我收到以下错误消息:Method range of object _worksheet failed
尝试使用变量作为范围长度在 excel 中选择范围时。
下面是我的代码片段:
Private Function copyAmount(startRange As Integer, endRange As Integer)
Dim startRng As String
Dim endRng As String
startRng = "A" & Str(startRange)
endRng = "A" & Str(endRange)
activateBook ("book2.xlsm")
Set rng = Range(startRng, endRng)
Workbooks("book2.xlsm").Sheets(1).Range(rng).Select
Selection.Copy
activateBook ("Book1.xlsm")
Range("D3").Select
Selection.PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End Function
任何帮助将不胜感激。