VBA:数组项目之后循环反复的减少已被删除? [英] VBA: Decrease iterations of loop after an array item has been deleted?
本文介绍了VBA:数组项目之后循环反复的减少已被删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在VBA为Excel:
In 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
如何降低循环迭代之后,我删除了阵列项目之一?
How can I decrease the iterations of the loop after I have deleted one of the array items?
推荐答案
您会好得多使用while循环,而不是为循环。此外,您可以在一个变量存储UBound函数(artMaster)。
You would be much better off using WHILE loops instead of FOR loops. Also, you could store UBound(artMaster) in a variable.
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
这篇关于VBA:数组项目之后循环反复的减少已被删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文