Two-column Listbox displayed in two Excel cells

Solved
chrisdemontigny Posted messages 70 Registration date   Status Member Last intervention   -  
chrisdemontigny Posted messages 70 Registration date   Status Member Last intervention   -
Hello,

I found the following code to retrieve a range of cells into a listbox:

Option Explicit
Private Sub UserForm_Initialize()
Dim TabTemp As Variant
'Load a range of cells into the variable TabTemp
TabTemp = Sheets("40101").Range("A1:b11").Value
'Define the number of columns for the ListBox.
ListBox1.ColumnCount = UBound(TabTemp)
'Load the array into the ListBox
ListBox1.List = TabTemp
End Sub

The first step is therefore done.

Now that I have made a choice in my listbox, I would like the selection made in my listbox (the two cells) to be displayed in two other cells, for example C4 and C5.
If I request ListBox1.Value, it only returns the first value.

Could you help me?

Feel free to tell me if I’m not clear.

Thanks very much in advance

Configuration: Windows / Chrome 41.0.2272.89

1 answer

  1. michel_m Posted messages 18903 Registration date   Status Contributor Last intervention   3 320
     
    Hello

    to extract the 2nd column of a listbox with N columns
    try
    range("B2")=ListBox1.List(ListBox1.ListIndex, 1)
    2nd col=1 because we start at 0

    From a valuable VBA tutorial with userforms:
    https://silkyroad.developpez.com/VBA/ControlesUserForm/#LII-G
    Michel
    0
    1. chrisdemontigny Posted messages 70 Registration date   Status Member Last intervention  
       
      Thank you very much.
      0