0

When I run the code below I get an error: Paste Special method of Range class failed. Any idea why this may be? The line i get this error on is marked with "->>"

    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
  • You've got unqualified `Cells` calls, but easier to just paste into the top left cell: `shiftLines.Cells(q, 1).PasteSpecial ...` – BigBen Sep 17 '20 at 18:11
  • 1
    you can skip the inner loop using `Resize()`: `shiftlines.Range(shiftlines.Cells(q, 1), shiftlines.Cells(q, 6)).Resize(, .Cells(i, 3).Value).Value = .Range(.Cells(i, 1), .Cells(i, 6)).Resize(, .Cells(i, 3).Value).Value` – Scott Craner Sep 17 '20 at 18:15

0 Answers0