VBA循环迭代至约700次时Excel崩溃问题求助
VBA循环迭代数千次时Excel崩溃问题
我编写的VBA代码LottoSearch在循环迭代至数千次(比如上限设为1000)时会导致Excel崩溃,仅当循环上限设为650或更低时能正常运行。我已经确认使用的是最新版Microsoft 365 Excel,内存和CPU资源充足,同时尝试了商务版和家庭版Excel,问题依旧。请问是否有其他人遇到过此类问题?
Sub LottoSearch() Dim stopRunUp As Integer stopRunUp = 0 For i = 2 To 1000 lottoNum = Cells(i, 3).Value If lottoNum = 3957481 Then Cells(2, 6).Value = Cells(i, 1).Value Cells(2, 7).Value = Cells(i, 2).Value Cells(2, 8).Value = lottoNum MsgBox ("Congratulations " + Str(Cells(2, 6).Value) + " " + Str(Cells(2, 7).Value)) End If If lottoNum = 5865187 Then Cells(3, 6).Value = Cells(i, 1).Value Cells(3, 7).Value = Cells(i, 2).Value Cells(3, 8).Value = lottoNum End If If lottoNum = 2817729 Then Cells(4, 6).Value = Cells(i, 1).Value Cells(4, 7).Value = Cells(i, 2).Value Cells(4, 8).Value = lottoNum End If If lottoNum = 2275339 And stopRunUp = 0 Then Cells(5, 6).Value = Cells(i, 1).Value Cells(5, 7).Value = Cells(i, 2).Value Cells(5, 8).Value = lottoNum stopRunUp = 1 End If If lottoNum = 5868182 And stopRunUp = 0 Then Cells(5, 6).Value = Cells(i, 1).Value Cells(5, 7).Value = Cells(i, 2).Value Cells(5, 8).Value = lottoNum stopRunUp = 1 End If If lottoNum = 1841402 And stopRunUp = 0 Then Cells(5, 6).Value = Cells(i, 1).Value Cells(5, 7).Value = Cells(i, 2).Value Cells(5, 8).Value = lottoNum stopRunUp = 1 End If Next i End Sub
内容的提问来源于stack exchange,提问作者Andrew Jessberger
相关产品推荐
相关产品推荐

