wwbwb
Well-known Member
- Joined
- Oct 20, 2003
- Messages
- 513
Greetings all,
I have a userform that I use to input names on a sheet. When the userform opens, textbox1 will populate depending on if a certain cell contains a name based on this line.
UserForm2.TextBox1.Value = Worksheets("list").Range("e" & res).Value
This works fine. I recently added the following code to the userform to have a listbox appear to give the user suggestions as they type a name into textbox1.
Everything works fine, with one little hang up. When the userform opens, and textbox1 populate with nothing, great. It works as expected. When the userform opens, and textbox1 populates with something, the listbox is visible. It goes away if I go to another box like it should. I understand it does because textbox1 changed, but I'd like to find a way for it to only appear when a user types something. Any thoughts?
I have a userform that I use to input names on a sheet. When the userform opens, textbox1 will populate depending on if a certain cell contains a name based on this line.
UserForm2.TextBox1.Value = Worksheets("list").Range("e" & res).Value
This works fine. I recently added the following code to the userform to have a listbox appear to give the user suggestions as they type a name into textbox1.
Code:
Private Sub textbox1_change()
'Code adapted from youtube.com/watch?v=e-3DrNiQ31I
Dim i As Integer
ListBox1.Clear
For i = 2 To 900
If UCase(Left(Worksheets("list").Cells(i, 5), Len(TextBox1.Text))) = UCase(TextBox1.Text) Then
ListBox1.AddItem Worksheets("List").Cells(i, 5)
End If
Next i
ListBox1.Visible = True
End Sub
Private Sub TextBox1_Exit(ByVal cancel As MSForms.ReturnBoolean)
On Error Resume Next
ListBox1.Visible = False
End Sub
Private Sub listbox1_dblclick(ByVal cancel As MSForms.ReturnBoolean)
TextBox1.Text = ListBox1.List(ListBox1.ListIndex)
ListBox1.Visible = False
End Sub
Private Sub UserForm_Initialize()
ListBox1.Visible = False
End Sub
Everything works fine, with one little hang up. When the userform opens, and textbox1 populate with nothing, great. It works as expected. When the userform opens, and textbox1 populates with something, the listbox is visible. It goes away if I go to another box like it should. I understand it does because textbox1 changed, but I'd like to find a way for it to only appear when a user types something. Any thoughts?