MultiSelect & order of choose

A

Adax

Hello! Excel 2003, form and ListBox (MultiSelect and frmListStyleOption).
User choose some positions from the ListBox and I must to know how was order
of this choose? I want this information to order results in the sheet. For
example: I can choose position 2,3,4 of the listbox, but ones in order: 234,
next 432, 342... Is it possible get this information of choose order in
VBA? Help me please! Greetings!
 
P

Per Jessen

Hi

Look at this example.

Create a userform with a listbox and a CommandButton, and paste this
code. Remember that the first item in the listbox is item number 0.

Option Base 1
Dim SelOrder()
Dim Counter


Private Sub CommandButton1_Click()
For n = 1 To UBound(SelOrder)
mStr = mStr & SelOrder(n)
Next
MsgBox (mStr)
End Sub

Private Sub ListBox1_Mouseup(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
Counter = Counter + 1

ReDim Preserve SelOrder(Counter)
SelOrder(Counter) = Me.ListBox1.ListIndex
End Sub


Private Sub UserForm_Initialize()
For c = 1 To 10
Me.ListBox1.AddItem "Item " & c
Next
End Sub

Hopes this helps
 
O

OssieMac

You could possibly handle it with code similar to this. However, you should
realize that the user could remove a selection after previously selecting it
and therefore that needs to be handled as per the comment.

Private Sub ListBox1_Change()

If ListBox1.Selected(ListBox1.ListIndex) Then
MsgBox "Value selected = " & _
ListBox1.List(ListBox1.ListIndex)
'Code here in lieu of msgbox to save the value _
to a list on worksheet
Else
MsgBox "Value cleared = " & _
ListBox1.List(ListBox1.ListIndex)
'Code here in lieu of msgbox to remove value _
from saved list on worksheet
End If

End Sub
 
D

Dave Peterson

As a user, I would find this irritating -- especially if I make mistakes and
click on the wrong item in the wrong order.

Have you thought about having a "move up" and "move down" button near the
listbox.

Or even using two listboxes and moving them in the order the user wants. (Move
right, move left, ...)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top