+ Reply to Thread
Results 1 to 13 of 13

Filling Listbox with more than 10 columns with array made from table with hidden columns

  1. #1
    Forum Contributor
    Join Date
    08-20-2019
    Location
    Mumbai
    MS-Off Ver
    Office 365
    Posts
    101

    Filling Listbox with more than 10 columns with array made from table with hidden columns

    Hi,

    I have a worksheet(code name: "ServLogSheet") having transactions table named "ServLogTbl". The table has 20 columns.

    I need to fill up a listbox (lbCustLog) to display only some of the columns from the table.

    I used the below code to do it. This worked till the number of columns to be displayed was up to 10.

    Please Login or Register  to view this content.
    Now, I need to display more than 10 columns from the ServLogTbl. Based on my search I found that the limit of listbox property columncount = 10 can be overcome if I use an array to fill the listbox using .list

    I can hide the not to be displayed columns of the ServLogTbl in the code. How do I select the visible table to fill an array? I tested the below code but only the first column of the table was filled in the array.

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    08-20-2019
    Location
    Mumbai
    MS-Off Ver
    Office 365
    Posts
    101

    Re: Filling Listbox with more than 10 columns with array made from table with hidden colum

    With the same logic : Apart from hiding columns, can I also apply filters to the table columns and fill an array with the visible part of the table.

  3. #3
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Filling Listbox with more than 10 columns with array made from table with hidden colum

    Yes you can loop through the visible cells. You'll need to populate an array and then assign that to the List property of the control, rather than using AddItem, if you need more than 10 columns.
    Rory

  4. #4
    Registered User
    Join Date
    11-04-2014
    Location
    Portugal
    MS-Off Ver
    XL2013/XL365
    Posts
    88

    Re: Filling Listbox with more than 10 columns with array made from table with hidden colum

    See if the attached example helps.
    If you want to hide some column in ListBox just put in "ListBox1.ColumnWidths", zero value for that column
    Attached Files Attached Files

  5. #5
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,302

    Re: Filling Listbox with more than 10 columns with array made from table with hidden colum

    Adapted from one of my previous contributions.
    Some of the code/approach may be of assistance.
    Sheet 2 is used as a temporary sort storage.
    torachan.
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    08-20-2019
    Location
    Mumbai
    MS-Off Ver
    Office 365
    Posts
    101

    Re: Filling Listbox with more than 10 columns with array made from table with hidden colum

    JCabral, Thanks. It helps. Like the idea of setting the column with to 0 in listbox. Makes it easy to filter out columns.

    I am using labels on top of the listbox as headers for the listbox columns. The normal ColumnHeads property doesn't work as I am not using the RowSource to populate the listbox. Now for cases where my listbox width is not enough to display all the columns, i.e. when there is a horizontal scroll bar in the listbox , how do I get the Column headers? Is there any workaround?

  7. #7
    Registered User
    Join Date
    11-04-2014
    Location
    Portugal
    MS-Off Ver
    XL2013/XL365
    Posts
    88

    Re: Filling Listbox with more than 10 columns with array made from table with hidden colum

    Quote Originally Posted by hemantparmar View Post
    JCabral, Thanks. It helps. Like the idea of setting the column with to 0 in listbox. Makes it easy to filter out columns.

    I am using labels on top of the listbox as headers for the listbox columns. The normal ColumnHeads property doesn't work as I am not using the RowSource to populate the listbox. Now for cases where my listbox width is not enough to display all the columns, i.e. when there is a horizontal scroll bar in the listbox , how do I get the Column headers? Is there any workaround?
    hemantparmar

    See if this help
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    08-20-2019
    Location
    Mumbai
    MS-Off Ver
    Office 365
    Posts
    101

    Re: Filling Listbox with more than 10 columns with array made from table with hidden colum

    Thanks JCabral. It works perfect.

    Can I request you to look at another thread which is for the same project of mine. It is about Creating a new Array(smaller) from the original Array depending on some filter condition. I know how to manage the filter conditions(using multiple IFs). I need help on creating a smaller array from a Bigger Array.

    https://www.excelforum.com/excel-pro...ml#post5224305

  9. #9
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,302

    Re: Filling Listbox with more than 10 columns with array made from table with hidden colum

    regarding your post #8, look at the method used in my post #5

  10. #10
    Forum Contributor
    Join Date
    08-20-2019
    Location
    Mumbai
    MS-Off Ver
    Office 365
    Posts
    101

    Re: Filling Listbox with more than 10 columns with array made from table with hidden colum

    @JCabral,

    There is a challenge I am facing with the below code of populating the listbox.

    Please Login or Register  to view this content.
    This code is very much useful for populating more than 10 columns, hiding unwanted columns and setting column heads. However, it gives it gives "unspecified error (80004005)". And I think the reason is as follows.

    I am using Advanced Filter method to copy part of the full data table in a new sheet, and defining that filtered range(lbRange) as the range for list box in this line .RowSource = lbRange.Address(external:=True) of the above code.

    This works fine for the first instance of this code.

    There are multiple combo boxes that act as filters on the user form. Every time a combobox value changes, the Advanced Filter method is applied to get a new set of range to be filled in the listbox. And I think that's where RowSource method doesn't work. I think when RowSource is used you can not change that data on worksheet during the code.

    Below is the full code for the sub that gets called for every change in the various combo box value. I get error on the first two line itself - unspecified error (80004005).

    ServLogTbl is the full Data Table on ServLogSheet.
    I have added one more sheet called ServLogFiltSheet, to define the Advanced filter criteria range and also to give a CopyToRange as cell A4 on it.

    Please Login or Register  to view this content.

    The reason you suggested me to use the rowsource method of filling the list box was to accommodate the ColumnHeads.

    Is there any other way to achieve this:
    1. Get more than 10 columns & Column Heads (for listbox having horizontal scroll bar)
    2. Allow repopulating of listbox based on changes in multiple combo box values - Advanced filter is the best option for me to do this.
    3. The other option is to store the new range obtained from Advanced filter in an array and populate the listbox using .list = NewArray. BUT can I get the Column Heads in this case?

  11. #11
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,302

    Re: Filling Listbox with more than 10 columns with array made from table with hidden colum

    Rowsource is the only method of populating listboxes with headers and it is the worst method to use and is only appropriate to use in low level apps.


  12. #12
    Registered User
    Join Date
    11-04-2014
    Location
    Portugal
    MS-Off Ver
    XL2013/XL365
    Posts
    88

    Re: Filling Listbox with more than 10 columns with array made from table with hidden colum

    The reason you suggested me to use the rowsource method of filling the list box was to accommodate the ColumnHeads.

    Is there any other way to achieve this:
    1. Get more than 10 columns & Column Heads (for listbox having horizontal scroll bar)
    2. Allow repopulating of listbox based on changes in multiple combo box values - Advanced filter is the best option for me to do this.
    3. The other option is to store the new range obtained from Advanced filter in an array and populate the listbox using .list = NewArray. BUT can I get the Column Heads in this case? - NO


    Hi hemantparmar

    I am a beginner in VBA.
    But I think the torachan gave the correct answer to your doubts.
    Unfortunately the investment in improving VBA has been nil, this is one of the gaps in VBA. The only solution I find is to decrease the number of columns in ListBox and put in Labels, the equivalent of Headers. When it is not possible I put nothing.
    Everything I develop is within the company, so it's easier to explain what the values in each column are.
    Another option that I don't quite understand may be Listview.

    I can however try to see if I can help but for that I need a practical example, with fictional data, and the expected result. But as I said I'm very new to this from the VBA so I can't promise to be able to help.

    See this link - https://youtu.be/7d4BPgJkUuw
    Last edited by JCabral; 11-06-2019 at 08:24 PM.

  13. #13
    Forum Contributor
    Join Date
    08-20-2019
    Location
    Mumbai
    MS-Off Ver
    Office 365
    Posts
    101

    Re: Filling Listbox with more than 10 columns with array made from table with hidden colum

    This was solved as follows. With few simple steps. Hope this would be useful for someone.

    @JCabral: used column width to zero for unwanted list columns
    @Torachan: used the array and .List method

    Apart from the above two methods, I managed to keep the column heads (external labels) by going back to basics: increase the userform size. Used almost the full screen size(width 955) and reducing the column widths to bare minimum.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Distribute array over multiple columns in listbox
    By marco1612 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-24-2019, 07:13 AM
  2. Filling in multiple columns from a separate corresponding table
    By knguyen777 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-29-2013, 03:13 PM
  3. Filling 2 columns in Listbox
    By Feloni in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-01-2013, 08:18 AM
  4. Replies: 0
    Last Post: 09-13-2012, 11:10 AM
  5. Replies: 2
    Last Post: 08-16-2012, 01:41 PM
  6. Hidden columns in pivot table source data
    By Kaigi in forum Excel General
    Replies: 2
    Last Post: 07-17-2009, 09:34 AM
  7. using listbox picks to make array of columns
    By fern in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-11-2005, 05:44 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1