Dim s As String Dim i As Long s = "要加入的字符串" For i = Combo1.ListCount - 1 To 0 Step -1 If s = Combo1.List(i) Then Exit For Next If i = -1 Then Combo1.AddItem s End If
补充下 if i = 0 then
Option ExplicitPrivate Sub Command1_Click() Dim i As Long Dim S As String
S = "12345" '需要增加的项
For i = 0 To Combo1.ListCount - 1 If Combo1.List(i) <> S Then '继续循环 Else Exit Sub '不添加 End If Next
Dim i As Long
s = "要加入的字符串"
For i = Combo1.ListCount - 1 To 0 Step -1
If s = Combo1.List(i) Then Exit For
Next
If i = -1 Then
Combo1.AddItem s
End If
if i = 0 then
Dim i As Long
Dim S As String
S = "12345" '需要增加的项
For i = 0 To Combo1.ListCount - 1
If Combo1.List(i) <> S Then
'继续循环
Else
Exit Sub '不添加
End If
Next
Combo1.AddItem S '添加项S
End Sub