Tag: crash

N次迭代后屏幕不会更新

我在我的excel上运行了一个非常简单的“Snake”类游戏,这意味着我需要在我的main-while循环内不断更新屏幕。 “蛇”(基本上是一个彩色细胞)在20×20桌子内随机移动。 它运行好几秒钟,然而,一些点屏幕停止更新; ans excel停止响应,同时仍然运行代码。 这导致崩溃。 我用For循环取代了循环,避免了崩溃,但仍然停止更新,直到循环结束。 循环停止时,屏幕最后一次更新。 我还在每个函数之后join了“睡眠”语句,但这并没有帮助。 这里是主要的代码: Sub main() Dim table(20, 20) As Integer Dim index_move As Integer 'Position class contains only X and Y parameters Dim index_actual_head_pos As Position Set index_actual_head_pos = New Position Dim i As Long index_actual_head_pos.x = 5 index_actual_head_pos.y = 15 Application.ScreenUpdating = True For i = 1 […]

循环崩溃的Excel VBA

我一直在让我的代码运行通过条件循环和停止的问题。 这是我有什么: Do While True Dim i As Integer i = 2 If Cells(i, 1).Value <> "" And Not IsError(Cells(i, 2).Value) Then Range(Cells(i, 1), Cells(i, 22)).Copy Range(Cells(i, 1), Cells(i, 22)).PasteSpecial i = i + 1 Else Exit Do End If Loop 我想要做的是让程序检查一个单元格是不是空的,如果另一个单元格没有错误,如果满足条件,那么程序将复制某一行,粘贴它只是它的值,因为行中的一些单元格是一个公式。 出于某种原因,循环不会退出和Excel崩溃,我错过了什么?