【发布时间】:2013-06-09 00:54:59
【问题描述】:
我有一些代码无缘无故停止执行,也没有产生错误。会不会是内存问题?它正在操作的工作表大约有 1600 行,其中包含大量格式和条件格式,并且代码在插入一行后停止。这是停止的代码sn-p:
With wsBudget
TotalColumn = .Range("TotalColumn").Column
FormulaColumn = .Range("FormulaColumn").Column
If .Cells(lRow, 1).Interior.Color <> 14408946 Then 'OK to insert
cell.EntireRow.Copy
cell.Resize(RowCount, 1).EntireRow.Insert 'It stops after stepping into this line
.Cells(cell.Row - RowCount, 1).EntireRow.ClearContents
.Cells(cell.Row - RowCount - 1, FormulaColumn).Resize(RowCount + 1, 1).FillDown
.Cells(cell.Row - RowCount - 1, TotalColumn).Resize(RowCount + 1, 1).FillDown
.Cells(cell.Row - RowCount - 1, 1).Resize(RowCount, 1).Interior.Color = RGB(255, 255, 255) 'OK to insert or delete
Else
MsgBox "You must select a cell within a table before inserting a row."
Exit Sub
End If
End With
【问题讨论】:
-
调查
Exit Sub的工作原理、它的作用以及它何时出现在您的代码中。我建议逐步完成调试过程 -
您需要在代码中包含错误处理程序。如果您使用过
On error resume next,请将其删除。 '改为使用On error goto err_location:并将其路由到标签。使用Err对象,您可以检查问题。 -
也是,我不确定它是否是故意的,但是,停止的行和之前的行的引用不合格。应该是一个。 (点)在单元格关键字前面(注意大小写差异)。
-
@mehow:它没有到达 Exit Sub 行。我的代码在停止执行的那一行有一条注释:它是 ....entirerow.insert 行。
-
@Santosh:正如我在问题中所说,它不会产生错误,因此错误处理对我没有帮助。我知道它不会产生错误,因为我确实尝试过错误 goto。