更新了我的問題。我把我的表格的流程圖和截圖放在一起,這樣你們可以更好地理解。爲什麼當我嘗試運行我的VBA代碼時,我的excel停止響應?
當我開始運行這個時,Excel停止響應。我似乎無法找到問題所在。我希望有人能幫幫忙!我研究了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
你可以把一些信息關於單元格中的數據?這可能是因爲Excel VBA的內存量有限,所以循環大型工作表可能導致它變爲無效。 – McBoman
這條線應該做什麼? (1)'Dis.Cells(x,4).Value -Cheque.Cells(y,2)= Current' – arcadeprecinct
除了@CharlesWilliams已經提到的內容,您應該查看幾行: 4).Value -Cheque.Cells(y,2)= Current'。我相信這應該是'Current = Dis.Cells(x,4).Value - Cheque.Cells(y,2).Value'。另外,(2)'ElseIf Current
Ralph