Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA复制范围错误1004_Excel_Vba - Fatal编程技术网

Excel VBA复制范围错误1004

Excel VBA复制范围错误1004,excel,vba,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

运行此代码时出现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))
它指向复制行,我不知道这里出了什么问题。感谢您的帮助范围内的
单元格()
指的是活动工作表,而不是范围内的工作表()所指的工作表

您需要将
单元格()

Worksheets("Tablecorrected").Range(Worksheets("Tablecorrected").Cells(2 + 19 ... and so on.
或者使用With块来保存键入

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

Range()
中的
单元格()
引用的是活动工作表,而不是
Range()
引用的工作表。您需要将
单元格()<代码>工作表(“Tablecorrected”).Range(工作表(“Tablecorrected”).Cells(2+19…
等等。如下:
code
Worksheets(“Tablecorrected”).Range(工作表(“Tablecorrected”).Range(单元格(2+19*行,1+19*列),单元格(19+19*行,18+Col*19))。复制目的地:=工作表(“Scriptsheet”).Range(工作表(“Scriptsheet”)).范围(单元格(1,1),单元格(18,18))
code