sort listbox selected items

Spoulis19

Board Regular
Joined
Dec 31, 2010
Messages
56
How can the items that I have select in a listbox to be entered to cells according to the selection order. And NOT accordind the order of the listbox order.

(for example the 2nd select item to entered 2nd, the 3rd, 3rd etc)
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
You can use Private Sub ListBox1_Click() to capture which item is selected as it is selected. One way to do this would be to create a string variable for storing selctions, adding to it with each Click so that items are in orser in which they were selected.
 
Upvote 0
Try something like this:-
Code:
Option Explicit
Option Base 1
Dim xRay() As String
Dim c As Integer
'====================
Private Sub ListBox1_Click()
c = c + 1
ReDim Preserve xRay(c)
xRay(c) = ListBox1.Value
End Sub
'===============
Private Sub CommandButton1_Click()
Range("B1").Resize(c) = Application.Transpose(xRay)
c = 0
Erase xRay
End Sub
Regards Mick
 
Upvote 0
Selecting something by mistake needs to be catered for, as in processing a deselect

probably using Micks example search array for replica and make the entry empty or re shuffle the array then resize

In the doofus example that would be an instr and replace

But not a straight forward as it may at first appear
 
Upvote 0
Can somebody help me please how to handle the situation of deselecting an item in the above question and example.

Kind Regards
 
Upvote 0
If you add this commandbutton code to your userform, it will clear any previouly selected items, so you can start the selection again.
Code:
Private Sub CommandButton2_Click()
c = 0
Erase xRay
End Sub
Mick
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,722
Members
452,939
Latest member
WCrawford

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
Back
Top