Results 1 to 8 of 8

Thread: Maximum columns in a ListBox

  1. #1
    Senior Member
    Join Date
    Apr 2011
    Posts
    190
    Rep Power
    14

    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
    xl2007 - Windows 7
    xl hates the 255 number

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,122
    Rep Power
    10
    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 Sub
    Code:
    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)

  3. #3
    Senior Member
    Join Date
    Oct 2011
    Posts
    135
    Rep Power
    13
    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.

  4. #4
    Senior Member
    Join Date
    Apr 2011
    Posts
    190
    Rep Power
    14
    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

  5. #5
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,122
    Rep Power
    10
    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)

  6. #6
    Senior Member
    Join Date
    Apr 2011
    Posts
    190
    Rep Power
    14
    Admin
    You are right - thanks - that is what I will do.
    Rasm
    xl2007 - Windows 7
    xl hates the 255 number

  7. #7
    Junior Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0
    If you use AddItem you are indeed limited to 10 columns. Either RowSource or List are fine for more.

  8. #8
    Junior Member
    Join Date
    May 2020
    Posts
    1
    Rep Power
    0
    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.

Similar Threads

  1. Wrap Text On Spaces Up To A Maximum Number Of Characters Per Line
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 15
    Last Post: 12-20-2016, 09:47 AM
  2. Replies: 6
    Last Post: 05-22-2013, 02:23 AM
  3. Change listbox value
    By Tony in forum Excel Help
    Replies: 4
    Last Post: 12-04-2012, 08:58 PM
  4. Hide/Unhide Columns with Listbox
    By obed_cruz in forum Excel Help
    Replies: 2
    Last Post: 05-28-2011, 07:26 PM
  5. Using ListView - a Listbox on steroids
    By Rasm in forum Download Center
    Replies: 3
    Last Post: 04-09-2011, 03:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •