Put this code In a standard Module:
Option Explicit
Sub ShowMyUserForm()
MyUserForm.Show
End Sub
Put this code In the module For your userform:
Option Explicit
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim Employee As Variant
Dim Name As String
Dim firstaddress As String
If IsNull(ListBox1.Value) Then Exit Sub
Employee = Empty
With ActiveSheet.Range("a1:a500")
Name = ListBox1.Value
Set Employee = .Find(what:=Name, LookIn:=xlValues)
If Not Employee Is Nothing Then Employee.Rows.EntireRow.Select Else Exit Sub
End With
Unload Me
Set Employee = Nothing
End Sub
Private Sub UserForm_activate()
Dim MyList(9, 3)
Dim R As Integer
Application.ShowToolTips = True
With ListBox1
.ColumnCount = 1
.ColumnWidths = 75
.Width = 230
.Height = 110
.ControlTipText = "Click the Name, Job, or ID you're after"
End With
With ActiveSheet
For R = 0 To 9
MyList(R, 0) = .Range("A" & R + 1)
MyList(R, 1) = .Range("D" & R + 1)
MyList(R, 2) = .Range("G" & R + 1)
Next R
End With
ListBox1.List = MyList
End Sub
Private Sub listBox1_Click()
Dim EmpFound As Range
Dim fPath As String
With Range("myName")
Set EmpFound = .Find(ListBox1.Value)
On Error Resume Next
If EmpFound Is Nothing Then
Image1.Picture = LoadPicture(fPath & "nopic.gif")
Else
With EmpFound
fPath = ThisWorkbook.Path & "\"
On Error Resume Next
Image1.Picture = LoadPicture(fPath & "\" & ListBox1.Value & ".jpg")
If Err = 0 Then Exit Sub
Image1.Picture = LoadPicture(fPath & "nopic.gif")
End With
End If
End With
Set EmpFound = Nothing
End Sub
|