Consulting

Results 1 to 8 of 8

Thread: Sleeper: Add ColumnHead to a ListBox via VBA

  1. #1
    VBAX Regular
    Joined
    Dec 2004
    Posts
    93
    Location

    Question Sleeper: Add ColumnHead to a ListBox via VBA

    I'm filling a ListBox via VBA code and would like to have this ListBox shows ColumnHeads descriptions. Is there a way to assign ColumnHeads names using VBA?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    The only way to get column heads is to set the RowSource to the part of the range excluding the heading, and set the ColumnHead property. Could be done in VBA, but you can't load it from elsewhere and get column heads.

  3. #3
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Or you could use the extra listview control. With this control you can stipulate the columntext to be shown.

    Charlize

  4. #4
    VBAX Regular
    Joined
    Dec 2004
    Posts
    93
    Location
    Quote Originally Posted by Charlize
    Or you could use the extra listview control. With this control you can stipulate the columntext to be shown.

    Charlize
    Can you give more details, please. I'm not sure I got it.

  5. #5
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Take a look at this kb article http://vbaexpress.com/kb/getarticle.php?kb_id=916. When you still got some questions, you may ask them. This one deals with the columnheads (how to set them up) and filling the listviewlist with some data.

    Charlize

  6. #6
    MS Excel MVP VBAX Tutor
    Joined
    Mar 2005
    Posts
    246
    Location
    I just use a regular listbox, and put labels on the userform above the listbox. It's much easier than dealing with nonstandard controls, and the labels don't scroll away when the listbox is scrolled.

    I also often add functionality to the labels. I make them look more like a button, and when the user clicks on one, sort the data by that column. Pretty slick, they tell me.
    - Jon
    -------
    Jon Peltier, Microsoft Excel MVP
    Peltier Technical Services
    Tutorials and Custom Solutions
    http://PeltierTech.com
    _______

  7. #7
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Well, nice idea but I've had some problems with that scrolling. If your list is longer than the width that you can show, the working option for me was, at that time, a listview option. When your list is wider than the view of the box, when scrolling to the right, the columnheads also scroll. I believe that it's even possible to add that sorting thing with the listview.

    Although I must admit that it will be a little bit easier to create something like that with the listbox thing and labels (looking like a button). Are labels scrollable ? So when you scroll to the right of a listbox that the labels scroll with the scrollbar ? Or can you say that a certain line must always be visible that acts as a columnhead ?

    Charlize

  8. #8
    MS Excel MVP VBAX Tutor
    Joined
    Mar 2005
    Posts
    246
    Location
    I set up my listbox so it doesn't need to scroll sideways.

    I don't think you can lock a header row in a listbox, but then I don't remember ever trying. It doesn't work if you fill the listbox using code, only if you use RowSource, and gaining headers is not enough of a reason to constrain my listbox and userform by using RowSource.
    - Jon
    -------
    Jon Peltier, Microsoft Excel MVP
    Peltier Technical Services
    Tutorials and Custom Solutions
    http://PeltierTech.com
    _______

Posting Permissions

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