我有一个简单的代码,需要很长时间才能运行。我想知道是否有办法让这个运行更快?也许这部分(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