VBA复制范围错误1004
运行此代码时出现1004错误:
Dim Row As Integer Dim Col As Integer Row = Worksheets("Design").Cells(11, 22).Value Col = Worksheets("Design").Cells(12, 22).Value Worksheets("Tablecorrected").Range(Cells(2 + 19 * Row, 1 + 19 * Col), Cells(19 + 19 * Row, 18 + Col * 19)).Copy _ Destination:=Worksheets("Scriptsheet").Range(Cells(1, 1), Cells(18, 18))
它指向复制线,我不知道这里有什么问题。 感谢您的帮助
Range()
中的Cells()
指向活动工作表,而不是Range()
所引用的工作表。
您需要将Cells()
限定在适当的表单中。
Worksheets("Tablecorrected").Range(Worksheets("Tablecorrected").Cells(2 + 19 ... and so on.
或者为了保存input,你可以使用With Block
Dim Row As Integer Dim Col As Integer Row = Worksheets("Design").Cells(11, 22).Value Col = Worksheets("Design").Cells(12, 22).Value With Worksheets("Tablecorrected") .Range(.Cells(2 + 19 * Row, 1 + 19 * Col), .Cells(19 + 19 * Row, 18 + Col * 19)).Copy _ Destination:=Worksheets("Scriptsheet").Range(Worksheets("Scriptsheet").Cells(1, 1), Worksheets("Scriptsheet").Cells(18, 18)) End With