Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.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粘贴特殊失败问题_Excel_Vba_Syntax Error - Fatal编程技术网

Excel VBA粘贴特殊失败问题

Excel VBA粘贴特殊失败问题,excel,vba,syntax-error,Excel,Vba,Syntax Error,当我运行下面的代码时,我得到一个错误:Range类的粘贴特殊方法失败。知道为什么会这样吗?我获取此错误的行标记为“->>” 您有不合格的单元格调用,但更容易粘贴到左上角的单元格中:shiftLines.Cells(q,1).PasteSpecial…您可以使用Resize():shiftLines.Range(shiftLines.Cells(q,1),shiftLines.Cells(q,6)).Resize(,.Cells(i,3).Value=.Range(.Cells(i,1),.Cel

当我运行下面的代码时,我得到一个错误:Range类的粘贴特殊方法失败。知道为什么会这样吗?我获取此错误的行标记为“->>”


您有不合格的
单元格
调用,但更容易粘贴到左上角的单元格中:
shiftLines.Cells(q,1).PasteSpecial…
您可以使用
Resize()
shiftLines.Range(shiftLines.Cells(q,1),shiftLines.Cells(q,6)).Resize(,.Cells(i,3).Value=.Range(.Cells(i,1),.Cells(i,6))跳过内部循环.Resize(,.Cells(i,3).Value).Value
    For i = 2 To p
        For n = 1 To shiftop.Cells(i, 3).Value
            With shiftop
                .Range(.Cells(i, 1), .Cells(i, 6)).Copy
            End With
            ->>shiftlines.Range(Cells(q, 1), Cells(q, 6)).PasteSpecial Paste = xlPasteValues
            q = q + 1
        Next n
    q = wkb.Worksheets("Shift Lines").Range("A" & Rows.Count).End(xlUp).Row
    Next i