View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Andy Pope Andy Pope is offline
external usenet poster
 
Posts: 2,489
Default on Listbox in Userform....

To move list items up and down try

Private Sub CommandButton1_Click()

Dim strTemp As String
Dim lngIndex As Long

If ListBox1.ListIndex 0 Then
lngIndex = ListBox1.ListIndex
strTemp = ListBox1.List(lngIndex - 1)
ListBox1.List(lngIndex - 1) = ListBox1.List(lngIndex)
ListBox1.List(lngIndex) = strTemp
ListBox1.ListIndex = lngIndex - 1
End If

End Sub

Private Sub CommandButton2_Click()

Dim strTemp As String
Dim lngIndex As Long

If ListBox1.ListIndex = 0 And _
ListBox1.ListIndex < (ListBox1.ListCount - 1) Then
lngIndex = ListBox1.ListIndex
strTemp = ListBox1.List(lngIndex + 1)
ListBox1.List(lngIndex + 1) = ListBox1.List(lngIndex)
ListBox1.List(lngIndex) = strTemp
ListBox1.ListIndex = lngIndex + 1
End If

End Sub

Cheers
Andy

x taol wrote:

oh, no...
i don't want to move just.
i want to move of the item. for example,

item
aaa
bbb
ccc
ddd

in that case, if "ccc" is selected, press the Up button, the sequency is
that.
aaa
ccc
bbb
ddd


*** Sent via Developersdex http://www.developersdex.com ***


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info