2 Column ListBox, Selection data

I

ironhydroxide

I have a 2Column Listbox. I do not know how to get both columns to
variables, i have tried multiple ways and can seem to only get the first
column (which the User has Highlighted) into a variable. How do i get both
values (either in Lines down, or in a string format) into either two
variables or an array. Thanks

Ironhydroxide
 
I

ironhydroxide

Apparently I was not clear in my orignal Post. I have a 2Column ListBox in
my Userform. and so the links dont help me at all. but thanks anyway.
 
D

Dave Peterson

This worked ok for me:

Option Explicit
Private Sub CommandButton1_Click()
With Me.ListBox1
If .ListIndex < 0 Then
Exit Sub 'nothing selected
End If

MsgBox .List(.ListIndex, 0) & vbLf & .List(.ListIndex, 1)
End With
End Sub
Private Sub UserForm_Initialize()
With Me.ListBox1
.ColumnCount = 2
.ColumnWidths = "33;33"
.List = Worksheets("sheet1").Range("A1:B5").Value
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top