更改操作系统时,运行时错误“1004”“范围级别的复制方法失败”

我有一些原来在这里修改的代码。 当行的第一列中有一个C被删除并保存在另一个表中时。 这是一个todo list应用程序。

Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) ' Code goes in the Worksheet specific module Dim rng As Range ' Set Target Range Set rng = Target.Parent.Range("A1:A200") ' Only look at single cell changes If Target.Count > 1 Then Exit Sub ' Only look at that range If Intersect(Target, rng) Is Nothing Then Exit Sub ' Action if Condition(s) are met Select Case Target.Text Case "C" Target.EntireRow.Copy Sheets("Completed").Cells(Rows.Count, "A").End(xlUp).Offset(1) Target.EntireRow.Delete End Select End Sub 

该代码在Excel 2010上运行得非常好,但是失败并出现此错误:

 Run time error '1004' "Copy Method of Range Class Failed" 

在这里输入图像说明

这是你正在尝试? 您需要closures事件,否则Target.EntireRow.Delete将重新启动事件。 你可能也想看看这个

 Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) Dim lRow As Long '~~> For Excel 2007+ 'If Target.Cells.CountLarge > 1 Then Exit Sub If Target.Cells.Count > 1 Then Exit Sub On Error GoTo Whoa Application.EnableEvents = False If Not Intersect(Target, Range("A1:A200")) Is Nothing Then If Target.Value = "C" Then With Sheets("Completed") '~~> Find next available row in the output sheet lRow = .Range("A" & .Rows.Count).End(xlUp).Row + 1 Target.EntireRow.Copy .Rows(lRow) Target.EntireRow.Delete End With End If End If Letscontinue: Application.EnableEvents = True Exit Sub Whoa: MsgBox Err.Description Resume Letscontinue End Sub 
 Sheets("Completed").Cells(Rows.Count, "A").End(xlUp).Offset(1) 

需要是

 Sheets("Completed").Cells(Sheets("Completed").Rows.Count, "A").End(xlUp).Offset(1)