Data is added in 1 column instaed of 4 columns (in listbox)

G

Guest

Hi all,

I am adding a range of data (4 coloms wide) from a worksheet to a listbox
with a commandbutton.
However, the data is 4 coloms wide. The data added is put below each other
instead of besised each other..

What can I do to make the data in the 4 coloumns?

Please find below my code I use at this moment..


---------------------------------------------
Private Sub Commandbutton1_Click()
' bepalen hoe breed de kolommen moeten zijn
Me.ListBox1.ColumnWidths = "360;28;53;50"

'hier wordt de listbox range bepaald zodat de juiste range in het juiste
tabblad komt.
Dim dpv2 As Long
Dim dpv22 As Long

ListBox1.Clear
ListBox1.ColumnCount = 4
ListBox1.RowSource = ""
For dpv2 = 1 To 63
ListBox1.AddItem Sheets("DPV 2").Range("a" & dpv2).Value
ListBox1.AddItem Sheets("DPV 2").Range("b" & dpv2).Value
ListBox1.AddItem Sheets("DPV 2").Range("c" & dpv2).Value
ListBox1.AddItem Sheets("DPV 2").Range("d" & dpv2).Value
Next dpv2

End Sub
------------------------------------------

Arjan Bregman

*****
the knowledge is always there, maybe hidden, but it is there..
*****
 
M

Mike Woodhouse

Hi all,

I am adding a range of data (4 coloms wide) from a worksheet to a listbox
with a commandbutton.
However, the data is 4 coloms wide. The data added is put below each other
instead of besised each other..

What can I do to make the data in the 4 coloumns?

Try this, which I just lifted from
http://www.chalouhis.com/XLBLOG/archives/2005/01/18/filling-a-multi-column-listbox/

Const NumColumns = 3
Const NumRows = 10

Dim i As Integer, j As Integer

For i = 1 To NumRows
lstMyListBox.AddItem “Row†& i & “Column1″
For j = 1 To NumColumns - 1
lstMyListBox.List(i - 1, j) = “Row†& i & “Columnâ€
& j
Next j
Next i


HTH,

Mike
 

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