列表框之间的项目转移 Last Row Issue

Item transfer between Listboxes Last Row Issue

我有一个列表框,其中包含我想移动到另一个列表框的值,以便用户可以对项目进行排序。选择最后一个项目时,它只会移动该项目并删除其上方的值。我怎样才能让它像列表中的其他项目一样发挥作用?

仅供参考,这是一个单一的项目选择,如果这改变了什么

Option Explicit
Option Base 1

Private Sub Add_Click()
 Dim x As Integer, count As Integer
  count = Me.Unsorted.ListCount
    For x = 0 To count
        If Me.Unsorted.Selected(x) = True Then
            Me.Sorted.AddItem Me.Unsorted.List(x)
        End If
    Next x

    For x = count To 0 Step -1
        If Me.Unsorted.Selected(x) = True Then
            Me.Unsorted.RemoveItem x
        End If
    Next x

End Sub

你可以用这个

Private Sub Add_Click()
    Dim x As Integer
    Dim nSelecteds As Long

    With Me
        With .Unsorted
            ReDim selecteds(1 To .ListCount) As Long
            For x = .ListCount - 1 To 0 Step -1
                If .Selected(x) Then
                    nSelecteds = nSelecteds + 1
                    selecteds(nSelecteds) = x
                    Me.Sorted.AddItem .List(x)
                End If
            Next x
            If nSelecteds > 0 Then
                For x = 1 To nSelecteds
                    .RemoveItem selecteds(x)
                Next x
            End If
        End With
    End With
End Sub