View Full Version : Maximum columns in a ListBox
It seems the maximum number of columns in a ListBox is 10 - my code crashes when I fill the values if the count is >10 ---- does anybody know the maximum.
Thanks Rasm:confused:
Admin
12-17-2011, 10:09 AM
Hi Rasm,
How you load the values into the listbox ?
I tried both RowSource and Array and it works fine
Private Sub UserForm_Initialize()
Dim s As String
s = "a2:n14"
With Me.ListBox1
.ColumnCount = 14
.RowSource = s
.ColumnHeads = True
End With
End Sub
Private Sub UserForm_Initialize()
Dim a
a = [a2:n14]
With Me.ListBox1
.List = a
.ColumnCount = UBound(a, 2)
End With
End Sub
PcMax
12-17-2011, 12:40 PM
Hi,
I understand that the Listbox have a maximum of 30 columns!
Alternatively viewable using the Listview
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)
Admin
Below is my code to fill the ListBox - Guess my approach to reading values into the ListBox is very crude - however if I set 'LastRow=10' then it all works - in terms of being able to fill the ListBox
PcMax - ok - so the max is 30 columns - I was using ListView - but it is unstable - I had to change a bunch of ListView objecxts to ListBoxes - major pain.
With Worksheets("testing").UsedRange
LastRow = .Rows(.Rows.Count).Row
ColLast = .Columns(.Columns.Count).Column
'LastRow = 10
End With
With ListBox1
.ColumnCount = LastRow
.ListStyle = 1
.MultiSelect = 1
.Clear
For ii = 1 To ColLast
.AddItem Worksheets("testing").Cells(1, ii).Value
For i = 2 To LastRow
.List(ii - 1, i - 1) = Worksheets("testing").Cells(i, ii).Value
Next i
Next ii
End With
Admin
12-17-2011, 09:31 PM
Hi Rasm,
Rather than looping all those cells, why don't you use variant array like I did in my post above ?
BTW, I tested 50 columns and works fine.
Admin
You are right - thanks - that is what I will do.
:)Rasm
excelgeek
12-22-2011, 05:57 PM
If you use AddItem you are indeed limited to 10 columns. Either RowSource or List are fine for more.
Chanchan
05-04-2020, 12:44 PM
Hi Good Day!
I got error on this. Can you give me an example code of it. Wishing a simple system of it?
When I put the Admin answer code.
I got error on declared cells.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.