Thanks in Advance,
Sanjay
I added a couple of me.repaints and doevents and that didn't seem to help.
This is what I did that reproduced the problem:
Option Explicit
Private Sub CommandButton1_Click()
Dim myTemp As String
With Me.ListBox1
If .ListIndex = -1 _
Or .ListIndex = 0 Then
Beep
Exit Sub
End If
myTemp = .List(.ListIndex - 1)
.List(.ListIndex - 1) = .List(.ListIndex)
.List(.ListIndex) = myTemp
.ListIndex = .ListIndex - 1
End With
Me.Repaint
DoEvents
End Sub
Private Sub CommandButton2_Click()
Dim myTemp As String
With Me.ListBox1
If .ListIndex = -1 _
Or .ListIndex = .ListCount - 1 Then
Beep
Exit Sub
End If
myTemp = .List(.ListIndex + 1)
.List(.ListIndex + 1) = .List(.ListIndex)
.List(.ListIndex) = myTemp
.ListIndex = .ListIndex + 1
End With
Me.Repaint
DoEvents
End Sub
Private Sub ListBox1_Click()
MsgBox Me.ListBox1.Value
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
For iCtr = 1 To 25
Me.ListBox1.AddItem "aaaa" & iCtr
Next iCtr
Me.CommandButton1.Caption = "Move Up"
Me.CommandButton2.Caption = "Move Down"
End Sub
But if I cleared out the list (I used a single column), the problem seemed to go
away.
I didn't see the problem when I did this:
Option Explicit
Private Sub CommandButton1_Click()
Dim myTemp As String
Dim myArr As Variant
Dim myIndex As Long
With Me.ListBox1
If .ListIndex = -1 _
Or .ListIndex = 0 Then
Beep
Exit Sub
End If
myIndex = .ListIndex
myTemp = .List(.ListIndex - 1)
myArr = Me.ListBox1.List
myArr(myIndex - 1, 0) = myArr(myIndex, 0)
myArr(myIndex, 0) = myTemp
.Clear
.List = myArr
.ListIndex = myIndex - 1
End With
End Sub
Private Sub CommandButton2_Click()
Dim myTemp As String
Dim myArr As Variant
Dim myIndex As Long
With Me.ListBox1
If .ListIndex = -1 _
Or .ListIndex = .ListCount - 1 Then
Beep
Exit Sub
End If
myIndex = .ListIndex
myTemp = .List(.ListIndex + 1)
myArr = Me.ListBox1.List
myArr(myIndex + 1, 0) = myArr(myIndex, 0)
myArr(myIndex, 0) = myTemp
.Clear
.List = myArr
.ListIndex = myIndex + 1
End With
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
For iCtr = 1 To 25
Me.ListBox1.AddItem "aaaa" & iCtr
Next iCtr
Me.CommandButton1.Caption = "Move Up"
Me.CommandButton2.Caption = "Move Down"
End Sub
--
Dave Peterson
ec3...@msn.com
--
Dave Peterson
ec3...@msn.com
>.
>