为什么我的excel停止响应,当我尝试运行我的VBA代码?

更新我的问题。 我把我的床单的stream程图和屏幕截图,让你们可以更好地理解。

图表

当我开始运行这个,Excel停止响应。 我似乎无法find错误的地方。 我希望有人能帮帮忙! 我研究了VBA代码,但是我认为还有一些东西还不够用?

Sub F110Loop() Dim x As Integer 'current amount Dim y As Integer Dim d As Double 'delta between Disbursement date and Cheque Release date Dim Current As Integer Dim Least As Integer Dim Dis As Worksheet Dim Cheque As Worksheet Dim wb As Workbook Set wb = ThisWorkbook Set Dis = wb.Sheets("Disbursements") Set Cheque = wb.Sheets("Cheque Info") wb.Activate For x = 4 To 600 Do While Dis.Cells(x, 9).Value > 1 'IF same amount, get row number to get corresponding date, reference that date For y = 3 To 600 If Dis.Cells(x, 6).Value = Cheque.Cells(y, 5).Value Then 'THEN get delta Current = Dis.Cells(x, 4).Value -Cheque.Cells(y, 2) 'IF current is less than the least delta ElseIf Current < Least Then 'THEN update new value of delta Current = Least Else 'copy paste the date (from the least delta row) Cheque.Cells(y, 2).Copy Destination:=Dis.Cells(x, 8) End If Next y Loop Next x End Sub 

可能你有一个无限循环,因为你永远不会改变Dis.Cells(x,9)

 Do While Dis.Cells(x, 9).Value > 1 ' make no change to Dis.Cells(x, 9) Loop 

你必须做一些事情:

 x = 4 Do while Dis.Cells(x,9).value > 1 x = x + 1 loop