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
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
xl2007 - Windows 7
xl hates the 255 number
Hi Rasm,
How you load the values into the listbox ?
I tried both RowSource and Array and it works fine
Code:Private Sub UserForm_Initialize() Dim s As String s = "a2:n14" With Me.ListBox1 .ColumnCount = 14 .RowSource = s .ColumnHeads = True End With End SubCode:Private Sub UserForm_Initialize() Dim a a = [a2:n14] With Me.ListBox1 .List = a .ColumnCount = UBound(a, 2) End With End Sub
Cheers !
Excel Range to BBCode Table
Use Social Networking Tools If You Like the Answers !
Message to Cross Posters
@ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)
Hi,
I understand that the Listbox have a maximum of 30 columns!
Alternatively viewable using the Listview
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
Last edited by DocAElstein; 07-07-2023 at 12:59 PM.
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.
Code: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
xl2007 - Windows 7
xl hates the 255 number
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.
Cheers !
Excel Range to BBCode Table
Use Social Networking Tools If You Like the Answers !
Message to Cross Posters
@ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)
Admin
You are right - thanks - that is what I will do.
Rasm
xl2007 - Windows 7
xl hates the 255 number
If you use AddItem you are indeed limited to 10 columns. Either RowSource or List are fine for more.
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.
Bookmarks