在 VBA for Excel 中:
For i = 0 To UBound(artMaster)
For j = i To UBound(artMaster)
If i <> j And artMaster(i).VDN = artMaster(j).VDN Then
Call DeleteArrayItem(artMaster, j)
End If
Next j
Next i
删除数组项之一后,如何减少循环的迭代次数?
最佳答案
使用 WHILE 循环而不是 FOR 循环会好得多。此外,您可以将 UBound(artMaster) 存储在变量中。
Dim I As Integer
Dim j As Integer
Dim n as Integer
i = 0
n = UBound(artMaster)
Do While i <= n
j = i + 1
Do While j <= n
If artMaster(i).VDN = artMaster(j).VDN Then
Call DeleteArrayItem(artMaster, j)
n = n - 1
End If
j = j + 1
Loop
i = i + 1
Loop
关于arrays - VBA:删除数组项后减少循环迭代次数?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9807576/