MoveDown + MoveUp

Moves an item in listbox up or down
Needs Lst1 as listbox name
Put code inside form (or userform)

Sub MoveDown()
 If Lst1.ListIndex < 0 Then Exit Sub
 If Lst1.ListIndex = Lst1.ListCount - 1 Then Exit Sub
 temp1 = Lst1.List(Lst1.ListIndex + 1)
 Lst1.List(Lst1.ListIndex + 1) = Lst1.List(Lst1.ListIndex)
 Lst1.List(Lst1.ListIndex) = temp1
 Lst1.ListIndex = Lst1.ListIndex + 1
End Sub
Sub MoveUp()
 If Lst1.ListIndex < 1 Then Exit Sub
 temp1 = Lst1.List(Lst1.ListIndex - 1)
 Lst1.List(Lst1.ListIndex - 1) = Lst1.List(Lst1.ListIndex)
 Lst1.List(Lst1.ListIndex) = temp1
 Lst1.ListIndex = Lst1.ListIndex - 1
End Sub

Views 1890 Downloads 924


ANmarAmdeen
612
Components VBA-Excel
Revisions

v1.0