PDA

View Full Version : Two Listbox questions



ProteanBeing
12-09-2007, 07:44 PM
1. How do I use a multi select list box (how do I know which ones are selected)

2. How do I place column headers into the listbox

Bob Phillips
12-10-2007, 02:42 AM
Load it



ary = [{"Bob","M", 123;"Lynne","F",898;"Amy","F",543}]

With ListBox1
For i = 1 To 3
.AddItem ary(i, 1)
For j = 2 To 3
.List(.ListCount - 1, j - 1) = ary(i, j)
Next j
Next i
End With


Retrieve from it



Dim i As Long
Dim j As Long
Dim iRow As Long
iRow = 10
With Me.ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) Then
For j = 1 To .ColumnCount
ActiveSheet.Cells(iRow, j).Value = .List(i, j - 1)
Next
iRow = iRow + 1
End If
Next i
End With



In the ListBox,
- set the ColumnCount property to number of columns,
- set ColumnHeads to True,
- set RowSource to the range of cells >>below<< the column headers text

The cells above this RowSource range will be used as column headers.