Userform Listbox Not Returning Selected Value (.Text)

duggie33

Board Regular
Joined
Nov 19, 2018
Messages
77
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
 

Some videos you may like

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

duggie33

Board Regular
Joined
Nov 19, 2018
Messages
77
Office Version
  1. 365
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,113,744
Messages
5,543,955
Members
410,586
Latest member
acadavid86
Top