Never say never JLGWhiz. Here is a method, different from Harald's (I think
it indicates what has moved more visually than Harald's), that allows you to
drag and drop items within a ListBox (on a UserForm). To move an item, press
the Shift key (think of the Shift key as a memory aid... Shift for shifting
items), either before or after selecting your item , click on the item and
drag the highlight to the position where you want that item to be located
at. The rule for how the items move out of the way is this... if you move
the item to a location earlier in the list than where it currently is, the
item you drop it on (and all items following it) moves down the list to make
room for the item... if you move the item to a location later in the list
than its where it currently is, the item you drop it on (and all preceding
items) moves up the list to make room for it. This movement rule allows you
to move the item to either end without problem (you would not be able to
slot the item at one end or the other if the list always moved in the same
direction). Okay, just paste the following code into the UserForm's code
window (see additional comments after the code)...
'*************** START OF CODE ***************
Dim DragIndex As Long
Dim SecondTime As Boolean
Dim DragActive As Boolean
Dim MouseDownFlag As Boolean
Private Sub ListBox1_Click()
With ListBox1
If SecondTime Then
SecondTime = False
Exit Sub
ElseIf MouseDownFlag Then
DragIndex = .ListIndex
MouseDownFlag = False
DragActive = True
SecondTime = True
End If
End With
End Sub
Private Sub ListBox1_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single)
With ListBox1
If Shift = 1 Then
MouseDownFlag = True
.ListIndex = -1
End If
End With
End Sub
Private Sub ListBox1_MouseUp(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single)
Dim ListText As String
With ListBox1
If DragActive Then
ListText = .List(DragIndex)
.RemoveItem DragIndex
.AddItem ListText, .ListIndex - (.ListIndex > DragIndex)
For X = 0 To .ListCount - 1
If .List(X) = ListText Then
.ListIndex = X
Exit For
End If
Next
End If
DragActive = False
End With
End Sub
'*************** END OF CODE ***************
If you want to test this out on a brand new UserForm, just place a ListBox
on the UserForm and use this event procedure to load up the ListBox with
sample data to drag around (don't forget to press the Shift key while
dragging)...
Private Sub UserForm_Initialize()
Dim X As Long
With ListBox1
For X = 0 To 30
.AddItem "Item #" & CStr(X + 1)
Next
End With
End Sub
Note... I put the ListBox name in With statements to make it easier to
change the referenced list box if you used a ListBox with a different name
than ListBox1. You would have to change the event declaration statements and
the With statements changing my example name of ListBox1 to whatever name
you gave your ListBox.