If multiple items are selected, the Value property cannot be used to retrieve the items. Instead, check whether the item is selected, then manipulate it as needed:

Private Sub btn_EmpOK_Click() Dim LastRow As Long, i As Integer

LastRow = Worksheets("Sheet2").Range("A65536").End(xlUp).Row + 1 Cells(LastRow, 1).Value = tb_EmpName.Value 'check the selection status of the items in the ListBox For i = 0 To lb_EmpPosition.ListCount - 1 'if the item is selected, add it to the sheet If lb_EmpPosition.Selected(i) = True Then

Cells(LastRow, 2).Value = Cells(LastRow, 2).Value & _ lb_EmpPosition.List(i) & "," End If Next i

Cells(LastRow, 3).Value = tb_HireDate.Value End Sub

The items in a ListBox start counting at 0, so if you use the ListCount property, you must subtract 1 from the result:

For i = 0 To lb_EmpPosition.ListCount - 1

0 0

Post a comment