【问题标题】:Run-time error on 'Copy' Method“复制”方法的运行时错误
【发布时间】:2015-03-03 15:57:19
【问题描述】:

我在复制方法上遇到运行时错误。

错误信息是:

“运行时错误 '-2147417848 (80010108)': 对象 'Range' 的方法 'Copy' 失败”

错误指向下面的代码行:

WST.Cells.Copy Destination:=WSD.Cells(1, 1)

这是工作簿中的所有 vba。

Option Explicit
Sub CreateReport()
Dim WSD As Worksheet
Dim WST As Worksheet
Dim ST As Long
Dim LastRow As Long
Dim LastRow1 As Long
Dim LastCol As Long
Dim FinalRow As Long
Dim i As Long


ST = 7
Set WSD = ActiveSheet
FinalRow = 42
Set WST = Sheets("BIF BR Prospects-Per Mgmt")
LastRow = WST.Cells(Rows.Count, 1).End(xlUp).Row
If LastRow > 1 Then
 WST.Cells(2, 1).Resize(LastRow - 1, 13).Copy
 WSD.Cells(FinalRow, 1).Insert Shift:=xlDown

 WSD.Cells(FinalRow, 13).Resize(LastRow - 1, 1).FormulaR1C1 = "=RC[-8]& ""/"" & RC[-2]"
 WSD.Cells(FinalRow, 5).Resize(LastRow - 1, 1).Value = WSD.Cells(FinalRow, 13).Resize(LastRow - 1, 1).Value
 WSD.Cells(FinalRow, 11).Resize(LastRow - 1, 1).ClearContents
 WSD.Cells(FinalRow, 13).Resize(LastRow - 1, 1).ClearContents

 WSD.Cells(FinalRow, 14).Resize(LastRow - 1, 1).FormulaR1C1 = "=IF(OR(RC[-5]="""",RC[-2]=""""),"""",RC[-5] & "" "" & RC[-2])"
 WSD.Cells(FinalRow, 9).Resize(LastRow - 1, 1).Value = WSD.Cells(FinalRow, 14).Resize(LastRow - 1, 1).Value
 WSD.Cells(FinalRow, 12).Resize(LastRow - 1, 1).ClearContents
 WSD.Cells(FinalRow, 14).Resize(LastRow - 1, 1).ClearContents


 WSD.Rows(FinalRow + LastRow - 1).Copy
 WSD.Rows(FinalRow & ":" & FinalRow + LastRow - 1).PasteSpecial Paste:=xlPasteFormats

 WSD.Cells(FinalRow + LastRow, 2).FormulaR1C1 = "=COUNTA(R[" & -LastRow & "]C[-1]:R[-2]C[-1])"
 WSD.Cells(FinalRow + LastRow, 5).FormulaR1C1 = "=SUM(R[" & -LastRow & "]C[5]:R[-2]C[5])"
 WSD.Rows(FinalRow + LastRow - 1).Delete

 WSD.Range(Cells(FinalRow - 1, 1), Cells(FinalRow + LastRow - 2, 10)).Select
 WSD.Sort.SortFields.Clear
 WSD.Sort.SortFields.Add Key:=Range(Cells(FinalRow, 6), Cells(FinalRow + LastRow - 2, 6)), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
 WSD.Sort.SortFields.Add Key:=Range(Cells(FinalRow, 4), Cells(FinalRow + LastRow - 2, 4)), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
 With WSD.Sort
    .SetRange Range(Cells(FinalRow - 1, 1), Cells(FinalRow + LastRow - 2, 10))
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .Apply
 End With

End If

FinalRow = FinalRow - ST
Set WST = Sheets("Funnel Status-Per AE info")
LastRow = WST.Cells(Rows.Count, 1).End(xlUp).Row
LastCol = WST.Cells(1, Columns.Count).End(xlToLeft).Column + 2
If LastRow > 1 Then
 Range(WST.Cells(1, 1), WST.Cells(LastRow, 1)).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range(WST.Cells(1, LastCol), WST.Cells(1, LastCol)), Unique:=True
 LastRow1 = WST.Cells(Rows.Count, LastCol).End(xlUp).Row
 WST.Cells(1, LastCol + 1) = 1
 WST.Cells(1, LastCol + 2) = 2
 WST.Cells(1, LastCol + 3) = 3
 WST.Cells(1, LastCol + 4) = 4
 WST.Cells(1, LastCol + 5) = 5

 WST.Cells(2, LastCol + 1).Resize(LastRow1 - 1, 5).FormulaR1C1 = "=COUNTIFS(C1,RC4,C2,R1C)"
 WST.Cells(2, LastCol + 1).Resize(LastRow1 - 1, 5).Value = WST.Cells(2, LastCol + 1).Resize(LastRow1 - 1, 5).Value
 WST.Cells(2, LastCol).Resize(LastRow1 - 1, 11).Copy
 WSD.Cells(FinalRow, 1).Insert Shift:=xlDown

 WSD.Rows(FinalRow + LastRow1 - 1).Copy
 WSD.Rows(FinalRow & ":" & FinalRow + LastRow1 - 1).PasteSpecial Paste:=xlPasteFormats

 Range(WST.Cells(1, LastCol), WST.Cells(LastRow1, LastCol + 5)).ClearContents
 WSD.Cells(FinalRow, 7).Resize(LastRow1 + 1, 1).FormulaR1C1 = "=SUM(RC[-5]:RC[-1])"
 WSD.Cells(FinalRow + LastRow1 - 1, 7) = ""
 WSD.Cells(FinalRow + LastRow1, 2).Resize(1, 5).FormulaR1C1 = "=SUM(R[" & -LastRow1 & "]C:R[-2]C)"
 WSD.Rows(FinalRow + LastRow1 - 1).Delete
End If

FinalRow = FinalRow - ST
Set WST = Sheets("BR Opened this week")
LastRow = WST.Cells(Rows.Count, 1).End(xlUp).Row
If LastRow > 1 Then
 WST.Cells(2, 1).Resize(LastRow - 1, 12).Copy
 WSD.Cells(FinalRow, 1).Insert Shift:=xlDown

 WSD.Cells(FinalRow, 12).Resize(LastRow - 1, 1).FormulaR1C1 = "=RC[-7]& ""/"" & RC[-2]"
 WSD.Cells(FinalRow, 5).Resize(LastRow - 1, 1).Value = WSD.Cells(FinalRow, 12).Resize(LastRow - 1, 1).Value
 WSD.Cells(FinalRow, 10).Resize(LastRow - 1, 1).ClearContents
 WSD.Cells(FinalRow, 12).Resize(LastRow - 1, 1).ClearContents

 WSD.Cells(FinalRow, 13).Resize(LastRow - 1, 1).FormulaR1C1 = "=IF(OR(RC[-6]="""",RC[-2]=""""),"""",RC[-6] & "" "" & RC[-2])"
 WSD.Cells(FinalRow, 7).Resize(LastRow - 1, 1).Value = WSD.Cells(FinalRow, 13).Resize(LastRow - 1, 1).Value
 WSD.Cells(FinalRow, 11).Resize(LastRow - 1, 1).ClearContents
 WSD.Cells(FinalRow, 13).Resize(LastRow - 1, 1).ClearContents



 WSD.Rows(FinalRow + LastRow - 1).Copy
 WSD.Rows(FinalRow & ":" & FinalRow + LastRow - 1).PasteSpecial Paste:=xlPasteFormats

 WSD.Cells(FinalRow + LastRow, 4).FormulaR1C1 = "=SUM(R[" & -LastRow & "]C[5]:R[-2]C[5])"
 WSD.Rows(FinalRow + LastRow - 1).Delete
End If

FinalRow = FinalRow - ST
Set WST = Sheets("REMOVED from BIF this week")
LastRow = WST.Cells(Rows.Count, 1).End(xlUp).Row
If LastRow > 1 Then
 WST.Cells(2, 1).Resize(LastRow - 1, 11).Copy
 WSD.Cells(FinalRow, 1).Insert Shift:=xlDown

 WSD.Cells(FinalRow, 13).Resize(LastRow - 1, 1).FormulaR1C1 = "=RC[-8]& ""/"" & RC[-2]"
 WSD.Cells(FinalRow, 5).Resize(LastRow - 1, 1).Value = WSD.Cells(FinalRow, 13).Resize(LastRow - 1, 1).Value
 WSD.Cells(FinalRow, 11).Resize(LastRow - 1, 1).ClearContents
 WSD.Cells(FinalRow, 13).Resize(LastRow - 1, 1).ClearContents


 WSD.Rows(FinalRow + LastRow - 1).Copy
 WSD.Rows(FinalRow & ":" & FinalRow + LastRow - 1).PasteSpecial Paste:=xlPasteFormats

 WSD.Cells(FinalRow + LastRow, 4).FormulaR1C1 = "=SUM(R[" & -LastRow & "]C[6]:R[-2]C[6])"
 WSD.Rows(FinalRow + LastRow - 1).Delete
End If

FinalRow = FinalRow - ST
Set WST = Sheets("BR Backlog of conf-unopened")
LastRow = WST.Cells(Rows.Count, 1).End(xlUp).Row
If LastRow > 1 Then
 WST.Cells(2, 1).Resize(LastRow - 1, 12).Copy
 WSD.Cells(FinalRow, 1).Insert Shift:=xlDown

 WSD.Cells(FinalRow, 12).Resize(LastRow - 1, 1).FormulaR1C1 = "=RC[-7]& ""/"" & RC[-2]"
 WSD.Cells(FinalRow, 5).Resize(LastRow - 1, 1).Value = WSD.Cells(FinalRow, 12).Resize(LastRow - 1, 1).Value
 WSD.Cells(FinalRow, 10).Resize(LastRow - 1, 1).ClearContents
 WSD.Cells(FinalRow, 12).Resize(LastRow - 1, 1).ClearContents

 WSD.Cells(FinalRow, 13).Resize(LastRow - 1, 1).FormulaR1C1 = "=IF(OR(RC[-6]="""",RC[-2]=""""),"""",RC[-6] & "" "" & RC[-2])"
 WSD.Cells(FinalRow, 7).Resize(LastRow - 1, 1).Value = WSD.Cells(FinalRow, 13).Resize(LastRow - 1, 1).Value
 WSD.Cells(FinalRow, 11).Resize(LastRow - 1, 1).ClearContents
 WSD.Cells(FinalRow, 13).Resize(LastRow - 1, 1).ClearContents




 WSD.Rows(FinalRow + LastRow - 1).Copy
 WSD.Rows(FinalRow & ":" & FinalRow + LastRow - 1).PasteSpecial Paste:=xlPasteFormats

 WSD.Cells(FinalRow + LastRow, 4).FormulaR1C1 = "=SUM(R[" & -LastRow & "]C[5]:R[-2]C[5])"
 WSD.Rows(FinalRow + LastRow - 1).Delete
End If

FinalRow = FinalRow - ST
Set WST = Sheets("BR Set-Confirmed this week")
LastRow = WST.Cells(Rows.Count, 1).End(xlUp).Row
If LastRow > 1 Then
 WST.Cells(2, 1).Resize(LastRow - 1, 12).Copy
 WSD.Cells(FinalRow, 1).Insert Shift:=xlDown

 WSD.Cells(FinalRow, 12).Resize(LastRow - 1, 1).FormulaR1C1 = "=RC[-7]& ""/"" & RC[-2]"
 WSD.Cells(FinalRow, 5).Resize(LastRow - 1, 1).Value = WSD.Cells(FinalRow, 12).Resize(LastRow - 1, 1).Value
 WSD.Cells(FinalRow, 10).Resize(LastRow - 1, 1).ClearContents
 WSD.Cells(FinalRow, 12).Resize(LastRow - 1, 1).ClearContents

 WSD.Cells(FinalRow, 13).Resize(LastRow - 1, 1).FormulaR1C1 = "=IF(OR(RC[-6]="""",RC[-2]=""""),"""",RC[-6] & "" "" & RC[-2])"
 WSD.Cells(FinalRow, 7).Resize(LastRow - 1, 1).Value = WSD.Cells(FinalRow, 13).Resize(LastRow - 1, 1).Value
 WSD.Cells(FinalRow, 11).Resize(LastRow - 1, 1).ClearContents
 WSD.Cells(FinalRow, 13).Resize(LastRow - 1, 1).ClearContents

 WSD.Rows(FinalRow + LastRow - 1).Copy
 WSD.Rows(FinalRow & ":" & FinalRow + LastRow - 1).PasteSpecial Paste:=xlPasteFormats

 WSD.Cells(FinalRow + LastRow, 4).FormulaR1C1 = "=SUM(R[" & -LastRow & "]C[5]:R[-2]C[5])"
 WSD.Rows(FinalRow + LastRow - 1).Delete

End If
Cells.EntireRow.AutoFit
WSD.Range(Columns(11).Address & ":" & Columns(Columns.Count).Address).ClearContents
WSD.Cells(1, 1).Select

End Sub
Sub ClearReport()

 Dim WSD As Worksheet
 Dim WST As Worksheet
 Set WSD = ActiveSheet
 Set WST = Sheets("GM")
 WST.Cells.Copy Destination:=WSD.Cells(1, 1)
End Sub
Sub Printing()

    With ActiveSheet.PageSetup
      .Orientation = xlLandscape
      .PaperSize = xlPaperLetter
      .Zoom = False
      .FitToPagesWide = 1
      .FitToPagesTall = False
    End With
End Sub

【问题讨论】:

  • 对我来说很好。您使用的是哪个版本的 Excel?
  • 版本 14.0.7143。我忘了提到错误是在 Windows 更新后开始的。看起来这是由 Excel 的安全更新 (kb2956081) 引起的。

标签: excel runtime-error vba


【解决方案1】:

我没有发现您的代码有问题,并且 Google 搜索显示了各种不同的信息/情况,其中会弹出此错误。来自the Windows Wiki page

“Excel 运行时错误 80010108 错误代码是由 Windows 操作系统中配置错误的系统文件以某种方式引起的。”

这可以解释为什么当其他人尝试相同的代码时它也适用。该网站上列出了一个修复实用程序。

【讨论】:

    【解决方案2】:

    由于 Excel 更新 KB2956081,对我来说同样的问题。问题不在宏中,而是在具有复制/过去操作的 Excel 中。如果整个工作表(所有单元格都被选中)被复制并粘贴到另一个工作表。 (或过去的特殊),所以 Excel 崩溃了。 (但如果选择不是所有单元格,Dos 不会崩溃)。包含此类命令 make 的宏会生成自动化错误。 如果删除了更新,则 Excel 会再次正常运行。

    【讨论】:

    • 嗨,这不是答案。如果您有要添加到问题的内容,请使用 cmets 字段。
    猜你喜欢
    • 2020-02-19
    • 2014-08-29
    • 1970-01-01
    • 2017-07-20
    • 1970-01-01
    • 2017-10-22
    • 1970-01-01
    • 1970-01-01
    • 2020-12-12
    相关资源
    最近更新 更多