M
Mas
Hi,
I am trying to add to list box available items based on
textbox text.
but my list box get added the same item several times.
what will be wrong with my following code?
Thanks
MAS
Private Sub TextBox1_Change()
Dim cell As Range
Dim Sh As Worksheet
Dim sString As String
If TextBox1.Text = "" Then
Label2.Caption = ""
Label1.Caption = ""
Else
Label2.Caption = "Available Title(s)"
End If
TextBox1.Text = UCase(TextBox1.Text)
Set Sh = Sheets("Define")
LR = Sh.Range("B" & Rows.Count).End(xlUp).Row
If TextBox1.Text = "" Then
ListBox1.Clear
Else
AmountOfChars = Len(TextBox1.Text)
For Each cell In Sh.Range("B2:B" & LR).Cells
sString = Left(cell.Value, AmountOfChars)
If sString = TextBox1.Text Then
ListBox1.AddItem cell.Value
End If
Next cell
End If
End Sub
I am trying to add to list box available items based on
textbox text.
but my list box get added the same item several times.
what will be wrong with my following code?
Thanks
MAS
Private Sub TextBox1_Change()
Dim cell As Range
Dim Sh As Worksheet
Dim sString As String
If TextBox1.Text = "" Then
Label2.Caption = ""
Label1.Caption = ""
Else
Label2.Caption = "Available Title(s)"
End If
TextBox1.Text = UCase(TextBox1.Text)
Set Sh = Sheets("Define")
LR = Sh.Range("B" & Rows.Count).End(xlUp).Row
If TextBox1.Text = "" Then
ListBox1.Clear
Else
AmountOfChars = Len(TextBox1.Text)
For Each cell In Sh.Range("B2:B" & LR).Cells
sString = Left(cell.Value, AmountOfChars)
If sString = TextBox1.Text Then
ListBox1.AddItem cell.Value
End If
Next cell
End If
End Sub