代码按预期工作,直到我尝试将值从一个范围移动到另一个范围的最后一行,此时我得到"运行时错误1004",所以必须做错事
范围" NewRng"确实产生了正确的字符串" $ A $ 1883:$ R $ 2105"如果手动输入到最后一行(替换" NewRng"参考),它会产生正确的结果。
提前致谢
Dim NevwebLR As String
With Sheets("NevWeb file")
NevwebLR = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
Dim DropShipLR As String
With Sheets("Drop Shipments")
DropShipLR = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
Dim NevwebLR1 As String
NevwebLR1 = NevwebLR + 1
Dim dropshipglue As Long
dropshipglue = Val(NevwebLR) + Val(DropShipLR)
Dim rng1 As Range, rng2 As Range
Dim NewRng As Range
With ThisWorkbook.Sheets("Results")
Set rng1 = .Range("A" & NevwebLR1)
Set rng2 = .Range("R" & dropshipglue)
Set NewRng = .Range(rng1, rng2)
Debug.Print NewRng.Address
End With
Sheets("results").Range(NewRng).Value = Sheets("Drop Shipments").Range("A1:R" & DropShipLR).Value
答案 0 :(得分:0)
您的目的地范围已经为Range
- 对象,因此请将最后一行更改为
NewRng.Value = Sheets("Drop Shipments").Range("A1:R" & DropShipLR).Value