With List3 If .ListCount > 1 Then i = 0 While i < .ListCount j = i + 1 While j < .ListCount If .List(i) = .List(j) Then .RemoveItem j End If j = j + 1 Wend i = i + 1 Wend End If End With //只是优化了一下,但是没变实质的东西!
多谢chenhw(我要回复)! 搞定了..... 为什么这么写?
循环变量有问题 RemoveItem之后本来是后一项的现在为当前项,你再j = j + 1,i = i + 1 就错过了这一项. 所以在RemoveItem之后,加上j = j - 1,i = i - 1来保持不漏项
If .ListCount > 1 Then
i = 0
While i < .ListCount
j = i + 1
While j < .ListCount
If .List(i) = .List(j) Then
.RemoveItem j
End If
j = j + 1
Wend
i = i + 1
Wend
End If
End With
//只是优化了一下,但是没变实质的东西!
为什么这么写?
RemoveItem之后本来是后一项的现在为当前项,你再j = j + 1,i = i + 1
就错过了这一项.
所以在RemoveItem之后,加上j = j - 1,i = i - 1来保持不漏项