更新了我的问题。我给出了我的表格的流程图和截图,以便你们能够更好地理解。
当我开始运行时,Excel停止响应。我似乎无法找到bug的位置。我希望有人能帮帮忙!我研究了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
答案 0 :(得分:4)
可能你有一个无限循环,因为你永远不会改变Dis.Cells(x,9)
Do While Dis.Cells(x, 9).Value > 1
' make no change to Dis.Cells(x, 9)
Loop
答案 1 :(得分:1)
你必须做类似的事情:
x = 4
Do while Dis.Cells(x,9).value > 1
x = x + 1
loop