K
kylekelsch
I'm not sure if this can be done and if it can I may be going at it
all wrong, but I have a combobox that adds items as I type, say if I
type "B" it adds all items from my list that begin with "B", Now what
I'm trying to do is make it so when I type the next letter it deletes
all the items from my combobox that do not contain those first 2
leters say if I type "Ba" anything that does not start with these 2
letters are removed and so on and so forth until when I finish typing
the word all I have in the list is that word.
Heres what I have so far. I'm new to VBA and know that I'm doing it
wrong but this is kind of how I figured it sould be, accept I don't
really know how to go about the removeitem part. Any input would be
greatly appreciated.
Private Sub ComboBox1_Change()
Dim ntotal As String
If Len(ComboBox1) > 0 Then
With Worksheets("Sheet1").Columns(1)
ntotal = 0
Do
If Left(Worksheets("Sheet1").Range("A1").Offset(ntotal,
0), Len(ComboBox1)) = _
Left(ComboBox1, Len(ComboBox1)) Then
ComboBox1.AddItem
(Worksheets("Sheet1").Range("A1").Offset(ntotal, 0).Value)
End If
With ComboBox1
If Left(Worksheets("Sheet1").Range("A1").Offset(ntotal,
0), Len(ComboBox1)) <> _
Left(ComboBox1, Len(ComboBox1)) Then
ComboBox1.RemoveItem
(Worksheets("Sheet1").Range("A1").Offset(ntotal, 0).Value)
End If
End With
ntotal = ntotal + 1
Loop Until Worksheets("Sheet1").Range("A1").Offset(ntotal,
0).Value = ""
End With
End If
End Sub
all wrong, but I have a combobox that adds items as I type, say if I
type "B" it adds all items from my list that begin with "B", Now what
I'm trying to do is make it so when I type the next letter it deletes
all the items from my combobox that do not contain those first 2
leters say if I type "Ba" anything that does not start with these 2
letters are removed and so on and so forth until when I finish typing
the word all I have in the list is that word.
Heres what I have so far. I'm new to VBA and know that I'm doing it
wrong but this is kind of how I figured it sould be, accept I don't
really know how to go about the removeitem part. Any input would be
greatly appreciated.
Private Sub ComboBox1_Change()
Dim ntotal As String
If Len(ComboBox1) > 0 Then
With Worksheets("Sheet1").Columns(1)
ntotal = 0
Do
If Left(Worksheets("Sheet1").Range("A1").Offset(ntotal,
0), Len(ComboBox1)) = _
Left(ComboBox1, Len(ComboBox1)) Then
ComboBox1.AddItem
(Worksheets("Sheet1").Range("A1").Offset(ntotal, 0).Value)
End If
With ComboBox1
If Left(Worksheets("Sheet1").Range("A1").Offset(ntotal,
0), Len(ComboBox1)) <> _
Left(ComboBox1, Len(ComboBox1)) Then
ComboBox1.RemoveItem
(Worksheets("Sheet1").Range("A1").Offset(ntotal, 0).Value)
End If
End With
ntotal = ntotal + 1
Loop Until Worksheets("Sheet1").Range("A1").Offset(ntotal,
0).Value = ""
End With
End If
End Sub