简体   繁体   English

运行时错误9-订阅超出范围

[英]Run time error 9 - subscription out of range

I am getting constant error of "out of range" but the reference of the range is correct, please help me to solve the error: the error or bug in the coding is highlighted as bold in the below mentioned code: 我收到“超出范围”的常量错误,但范围的引用是正确的,请帮助我解决错误:在下面提到的代码中,编码中的错误或错误以粗体突出显示:

Sub CopyStuff()

    **Sheets("Data-BNF").Range("D11:X76").Copy**
    Sheets("Storage-OI").Range("C" & Rows.Count).End(xlUp).Offset(2, 0).PasteSpecial xlPasteValues

End Sub

Modify the below and try: 修改以下内容,然后尝试:

Option Explicit

Sub Copy()

    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim Lastrow As Long

    With ThisWorkbook
        Set ws1 = .Worksheets("Data-BNF")
        Set ws2 = .Worksheets("Storage-OI")
    End With

    Lastrow = ws2.Cells(ws2.Rows.Count, "C").End(xlUp).Row

    ws1.Range("D11:X76").Copy
    'Try the **ONE of the below**
    ws2.Range("C" & Lastrow + 1).PasteSpecial Paste:=xlPasteValue
    ws2.Range("C" & Lastrow + 1).PasteSpecial xlPasteValues

End Sub

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

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