getting text for unselected listbox items

tgreddy

New Member
Joined
Feb 24, 2006
Messages
49
Hey everyone,

I've been stuck on this problem for quite a few hours and was hoping you could help me. I have two listboxes that contain roughly 5 items each. These items can be moved back and forth between the two listboxes...but when I'm done and click the "OK" button, some validation needs to be done. The validation involves going through each item in each listbox, but I'm running into a problem retrieving the text of each item in the listbox because they aren't selected.

So in short...my question is...how do I retrieve the text of an unselected listbox item if I know the index. Thanks.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
what's your meaning?

Paste your codes here.

Best Regards
 
Upvote 0
I guess for simplicity purposes...you could assume that I'm trying to dump the listbox items text into Sheet1. So what I want to do is look at the last listbox item and take the text and put it in A1, then I want to look at the 2nd to last item, take the text and put it in A2...etc...until I get to the top of the listbox. I tried the below code, but the bolded portion doesn't work. Thanks for the help in advance!

Range("A1").select
For i = Form1.IncludedSecurityListBox.ListCount - 1 To 0 Step -1 activecell.offset(0,i).value = Form1.IncludedSecurityListBox.Text(i)
Next i
 
Upvote 0
Try this.
Code:
Dim I As Long
For I = Form1.IncludedSecurityListBox.ListCount - 1 To 0 Step -1
    Range("A1").Offset(, I).Value = Form1.IncludedSecurityListBox.List(I)
Next I
By the way why are you looping backwards?
 
Upvote 0
Thanks. I haven't tried the code yet, but to answer your question, I'm looping backwards because my listbox is sorted in ascending order, but the list that is finally output needs to be in reverse order...so rather than going forward and having to re-sort the list...I figured I'd go backwards and save myself a step. Is there a quick way to sort a listbox?
 
Upvote 0

Forum statistics

Threads
1,214,638
Messages
6,120,676
Members
448,977
Latest member
moonlight6

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