Sub MoveListboxItem(ctrl As ListBox, ByVal FromIndex As Long, _
ByVal ToIndex As Long) Dim sText As String, lItemData As Long ' provide a default If FromIndex < 0 Then FromIndex = ctrl.ListIndex ' exit if argument not in range If ToIndex < 0 Or ToIndex > ctrl.ListCount - 1 Then Exit Sub With ctrl ' save text and data of the current item sText = .List(FromIndex) lItemData = .ItemData(FromIndex) ' remove the item .RemoveItem FromIndex ' add the item .AddItem sText, ToIndex .ItemData(.NewIndex) = lItemData ' select the new item .ListIndex = ToIndex End With End Sub |