Userform Listbox Not Returning Selected Value (.Text)

duggie33

Active Member
Joined
Nov 19, 2018
Messages
445
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have a Userform with two Listboxes and two Labels on it. Both Listboxes are populated in the Initialize procedure and one item is selected in each as a default when the user launches the Userform. I would like the Label1 to show the item selected in the Listbox1 and Label2 to show the item selected in Listbox2. This is an abbreviated version of what it will do and Labels could be substituted with Textboxes, I have the same issue no matter what.

The issue...Userform loads, Listboxes populate, one item in each is selected (using Listbox1.Selected(0) = True and Listbox2.Selected(1) = True). I try to get Labels to display the value selected in Listboxes (using Label1.Caption = Listbox1.Text and Label2.Caption = Listbox2.Text). Only one Listbox will display the selected item, the other is blank. Both Listboxes are Single Select. I am positive that the one that shows has changed with some change to the code or just by reloading the Userform but I cannot replicate when it changes or guess as to why it would switch from showing one to the other. When stepping through the code, I can see it select the items in both and when the form is shown there are selections in both, why does it not return the .Text value from both?

Hopefully I have adequately described the issue. Thanks in advance for your help.

Doug
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
It turns out that changing Listbox1.Text to Listbox1.List(Listbox1.ListIndex) and similar for Listbox2 makes both values display properly. I wish I understood why as it was a waste of hours searching and trying different things. If anyone can shed some light, it would be greatly appreciated.

Doug
 
Upvote 0
Solution

Forum statistics

Threads
1,223,888
Messages
6,175,207
Members
452,618
Latest member
Tam84

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