我有一些代码停止执行没有明显的原因,并没有产生一个错误。这可能是内存问题吗?它正在操作的工作表有大约1600行,包含大量格式和条件格式,插入行后代码停止。这里是它停止的代码片段:Excel VBA停止没有错误信息
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'是如何工作的,以及它在你的代码中发生了什么。我建议逐步执行调试过程 – 2013-06-12 22:59:44
您需要将错误处理程序包含到代码中。如果您已经使用了'在错误恢复下一个'然后删除它。 '改用'On error goto err_location:'并将其路由到标签。使用'Err'对象可以检查问题。 – Santosh
也是,而且我不确定它是否有意为之,但是,对于停止的行以及之前的行的引用不合格。应该是。 (点)在单元格关键字前(注意大小写区别)。 – sous2817