VBA复制范围错误1004

时间:2016-05-12 16:13:14

标签: excel vba

运行此代码时出现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))

它指向复制线,我不知道这里有什么问题。谢谢你的帮助

1 个答案:

答案 0 :(得分:3)

Cells()内的Range()指的是活动工作表而不是Range()所指的工作表。

您需要将Cells()限定为正确的表格。

Worksheets("Tablecorrected").Range(Worksheets("Tablecorrected").Cells(2 + 19 ... and so on.

或者为了保存输入,您将使用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