Userform Listbox Not Returning Selected Value (.Text)

duggie33

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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

duggie33

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

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,348
Messages
5,510,774
Members
408,809
Latest member
Matthiasek

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top