Forum Discussion

oteixeira62's avatar
oteixeira62
Copper Contributor
Jan 14, 2023
Solved

Store select item from listbox to textbox

I have this UserForm with a listbox of items stored in Sheet, column A. Whenever I select a country from the listbox, the country name is displayed in the textbox bellow the countries list. My goal ...
  • HansVogelaar's avatar
    Jan 14, 2023

    oteixeira62 

    Set the ColumnCount property of the list box to 2.

    In the UserForm_Initialize procedure, change

        ListBox1.List = Sheets("Sheet1").Range("A2:A" & Cells(Rows.Count, 2).End(xlUp).Row).Value

    to

        ListBox1.List = Sheets("Sheet1").Range("A2:B" & Cells(Rows.Count, 2).End(xlUp).Row).Value
    

     In the ListBox1_Change procedure, change

        If ListBox1.Selected(k) Then TextBox2.Value = ListBox1.Text

    to

        If ListBox1.Selected(k) Then TextBox2.Value = ListBox1.Column(1)

Resources