CopyPaste中的应用程序定义或对象定义错误

时间:2015-06-26 19:41:03

标签: vba excel-vba error-handling copy-paste excel

出于某种原因我收到了错误,但我找不到原因。它发生在复制/粘贴,但我不知道它会如何导致它。请帮忙

Sub CopyMain()
RowCountBack = 2
Dim n As Integer
RowCount = RowCount / 2
RowCountConst = RowCount
RowCount = RowCount + 1
For n = 1 To 100
    'If Cells(RowCount, 10).Value = "AR_Mag (ppm)" Then
    If InStr(1, Worksheets("RAW").Cells(RowCount, 7).Value, "AR_Mag", vbTextCompare) > 0 Then
        'Sheets("RAW").Range(Cells(RowCountBack, 1), Cells(RowCount, 10)).Copy
        WkSht.Range(Cells(RowCountBack, 1), Cells(RowCount, 10)).Copy Destination:= _
            Worksheets("AR_MAG").Range("a5") _
            .End(xlDown).Offset(2, 0)
        RowCount = RowCount + RowCountConst
        RowCountBack = RowCountBack + RowCountConst
    End If

这是经过大量编辑后的代码。原文在这里有类似的错误

If InStr(1, Worksheets("RAW").Cells(RowCount, 7).Value, "AR_Rot", vbTextCompare) > 0 Then
        wkb.Sheets("AR_ROT").Range(Cells(RowCountBack, 1), Cells(RowCount, 10)).Value = wkb.Sheets("RAW").Range(Cells(RowCountBack, 1), Cells(RowCount, 10))
        RowCount = RowCount + RowCountConst
        RowCountBack = RowCountBack + RowCountConst
    End If

正如你所看到的那样,两者都有相似的用途

1 个答案:

答案 0 :(得分:0)

我不知道为什么,但这是工作版

Range(Cells(RowCountBack, 1), Cells(RowCount, 10)).Copy Destination:=Sheets("AR_MAG").Range("A2")