Hallo,
Ik heb volgende code op het net gevonden. Nu had ik graag dat tijdens het uitvoeren van deze code "EMPLOYEE" in de listbox niet meer te voorschijn komt. Ik heb het bereik van de listbox aangepast waardoor employee verdwijnt en nu een blanco cel is. Weet er iemand hoe je de namen die er onder staan gewoon één rij naar boven kan schuiven zodat mijn listbox start met "Abraham lincoln".
Bedankt
'When a name in the listbox is double-clicked, select the corresponding row
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
'If you add more than 500 names you will need to increase this
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
'closes the form when you double-click on a name
Unload Me
Set Employee = Nothing
End Sub
Private Sub UserForm_activate()
Dim MyList(9, 3) 'as array type
Dim R As Integer
'The list box contains 1 data column.
'You can configure the number of columns, their width and height below
'as well as change the text in the ControlTipText of the listbox
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
'Define the list and where it's obtained from (Columns A, D, G in this example)
With ActiveSheet
'MyList (Row{0 to 9}, Column{0 to 2}) = the ranges given
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[/COLOR]
'populate the list box
ListBox1.List = MyList
End Sub
'This sub uses the list box to select the name on the spreadsheet
'and display their picture if one is found
Private Sub listBox1_Click()
Dim EmpFound As Range
Dim fPath As String
'selects the range to look for a name. You have to have a range
'named myName set up on column A. Go to insert-name-define to
'see how this one is set up.
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
'Look in the directory where this workbook is located.
fPath = ThisWorkbook.Path & "\"
On Error Resume Next
'If a matching picture is found then display it.
Image1.Picture = LoadPicture(fPath & "\" & ListBox1.Value & ".jpg")
'If No picture found then display the default picture.
If Err = 0 Then Exit Sub
Image1.Picture = LoadPicture(fPath & "nopic.gif")
End With
End If
End With
Set EmpFound = Nothing
End Sub
Ik heb volgende code op het net gevonden. Nu had ik graag dat tijdens het uitvoeren van deze code "EMPLOYEE" in de listbox niet meer te voorschijn komt. Ik heb het bereik van de listbox aangepast waardoor employee verdwijnt en nu een blanco cel is. Weet er iemand hoe je de namen die er onder staan gewoon één rij naar boven kan schuiven zodat mijn listbox start met "Abraham lincoln".
Bedankt
'When a name in the listbox is double-clicked, select the corresponding row
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
'If you add more than 500 names you will need to increase this
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
'closes the form when you double-click on a name
Unload Me
Set Employee = Nothing
End Sub
Private Sub UserForm_activate()
Dim MyList(9, 3) 'as array type
Dim R As Integer
'The list box contains 1 data column.
'You can configure the number of columns, their width and height below
'as well as change the text in the ControlTipText of the listbox
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
'Define the list and where it's obtained from (Columns A, D, G in this example)
With ActiveSheet
'MyList (Row{0 to 9}, Column{0 to 2}) = the ranges given
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[/COLOR]
'populate the list box
ListBox1.List = MyList
End Sub
'This sub uses the list box to select the name on the spreadsheet
'and display their picture if one is found
Private Sub listBox1_Click()
Dim EmpFound As Range
Dim fPath As String
'selects the range to look for a name. You have to have a range
'named myName set up on column A. Go to insert-name-define to
'see how this one is set up.
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
'Look in the directory where this workbook is located.
fPath = ThisWorkbook.Path & "\"
On Error Resume Next
'If a matching picture is found then display it.
Image1.Picture = LoadPicture(fPath & "\" & ListBox1.Value & ".jpg")
'If No picture found then display the default picture.
If Err = 0 Then Exit Sub
Image1.Picture = LoadPicture(fPath & "nopic.gif")
End With
End If
End With
Set EmpFound = Nothing
End Sub