我有一個簡單的代碼,需要很長時間才能運行。我想知道是否有辦法讓這個運行更快?也許這部分(Cells(i,「U」)。Value = Cells(n,「X」)。Value)不應該被使用2次!謝謝!iF Then Else code - 如何讓這個運行更快? VBA
For n = 3 To time_frame + 3
For i = 3 To 1002
If (Cells(i, "U").Value = Cells(n, "X").Value) And (Bed_in_use < 24) And Wait_L > 0 Then
Wait_L = Wait_L - (24 - Bed_in_use)
ElseIf (Cells(i, "U").Value = Cells(n, "X").Value) And (Bed_in_use < 24) And Wait_L <= 0 Then
Bed_in_use = Bed_in_use + 1
End If
Next i
Next n
MsgBox "The number of bed in use is " & Bed_in_use & ". There are " & Wait_L & " patients in the waiting list."
End Sub
你可以在行「U」和「X」創建一個數組的值,然後比較數組的值,而不是單元格的值。 – jcarroll
@jcarroll好的,請你讓我知道如何創建數組的值。謝謝。 – Zapata