UserForms & ListBox

TedMosby

New Member
Joined
Jan 8, 2009
Messages
4
I have a UserForm and within it is ListBox. I have a 2 CommandButtons which are for scrolling Up & Down the list of data within the ListBox.
My problem is that when I run this code it just moves the line of data Up or Down and not the highlighted bar.

How can I do this?

Rich (BB code):
Private Sub cmdUp_Click()
Dim ActionTemp As ActionDiary, iLi As Integer
iLi = Me.lstActions.ListIndex
If Not iLi = 0 Then
With ActionData(iLi)
ActionTemp = ActionData(iLi)
ActionData(iLi) = ActionData(iLi + 1)
ActionData(iLi + 1) = ActionTemp
End With
Call ClearActionsList
Call BuildActionsList
Me.lstActions.ListIndex = iLi - 1
End If
End Sub


Rich (BB code):
Rich (BB code):
Private Sub cmdDown_Click()
Dim ActionTemp As ActionDiary, iLi As Integer
iLi = Me.lstActions.ListIndex + 1
If Not iLi = Me.lstActions.ListCount Then
ActionTemp = ActionData(iLi + 1)
ActionData(iLi + 1) = ActionData(iLi)
ActionData(iLi) = ActionTemp
Call ClearActionsList
Call BuildActionsList
Me.lstActions.ListIndex = iLi
End If
End Sub

 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
I don't know what your called procedures are doing, but I had no problem incrementing the selection with this code (unless, of course, the last item was selected):

Code:
Private Sub CommandButton1_Click()
    With ListBox1
        .ListIndex = .ListIndex + 1
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,191,314
Messages
5,985,939
Members
439,990
Latest member
amsa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top