简体   繁体   English

剪切和粘贴范围vba

[英]cut and paste range vba

    For j = 1 To numrows - 1
        erow = Cells(Rows.count, 10 + j).End(xlUp).Row
        totalMins = Cells(erow, 10 + j)
        MsgBox (totalMins)
        Range(Cells(erow, 10 + j), Cells(erow, 10 + j).End(xlUp)).Cut
        Cells(20, 20).PasteSpecial xlPasteValues
    Next

Keep getting pastespecial range class failed error. 不断收到pastespecialrange类失败错误。 what is the reason this is failing and how could I correct my code. 这是什么原因导致失败,以及如何纠正我的代码。

You can't paste special from a cut. 您不能从剪切中粘贴特殊内容。 Use: 采用:

    For j = 1 To numrows - 1
       erow = Cells(Rows.count, 10 + j).End(xlUp).Row
       totalMins = Cells(erow, 10 + j)
       MsgBox (totalMins)
       Range(Cells(erow, 10 + j), Cells(erow, 10 + j).End(xlUp)).Cut Cells(20, 20)
    Next

Or better yet: 或者更好:

    For j = 1 To numrows - 1
       erow = Cells(Rows.count, 10 + j).End(xlUp).Row
       totalMins = Cells(erow, 10 + j)
       MsgBox (totalMins)
       Cells(20, 20) =Range(Cells(erow, 10 + j), Cells(erow, 10 + j).End(xlUp))
       Range(Cells(erow, 10 + j), Cells(erow, 10 + j).End(xlUp)).ClearContents
    Next

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM