【问题标题】:Application Defined or Object Defined Error in CopyPasteCopyPaste 中的应用程序定义或对象定义错误
【发布时间】:2015-09-13 20:46:32
【问题描述】:

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

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

如您所见,两个 if 的作用相似

【问题讨论】:

    标签: vba excel error-handling copy-paste


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多