Banner

Saturday, March 18, 2017

Display Contact In Listbox Userform VBA Excell





Private Sub UserForm_Initialize()
'listbox additem
Dim i As Long
For i = 2 To Application.WorksheetFunction.CountA(Sheet1.Range("A:A"))
Me.ListBox1.AddItem Sheet1.Cells(i, 1).Value
Next i
Me.ListBox1.Selected(0) = True
End Sub

Private Sub ListBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'search contact
Me.ListBox1.Clear
Dim i As Long
For i = 2 To Application.WorksheetFunction.CountA(Sheet1.Range("A:A"))
For x = 1 To 5
If Sheet1.Cells(i, 1).Value = Me.TextBox1.Text Then
Me.ListBox1.AddItem Sheet1.Cells(1, x).Value
Me.ListBox1.List(ListBox1.ListCount - 1, 1) = Sheet1.Cells(i, x).Value
End If
Next x
Next i
Me.ListBox1.Selected(0) = True
End Sub



Private Sub CommandButton1_Click()

'for back button

Me.ListBox1.Clear

Call UserForm_Initialize

End Sub



Private Sub ListBox1_Click()

'textbox fill

Me.TextBox1.Text = Me.ListBox1.Column(0)

End Sub

No comments:

Post a Comment

Please do not enter any spam message in comment box