+ Reply to Thread
Results 1 to 9 of 9

Add Listbox header using VBA

  1. #1
    Registered User
    Join Date
    01-11-2006
    Posts
    15

    Exclamation Add Listbox header using VBA

    I have Column A to BH in my excel sheet. I want to display column A, B ,C,E, G and BH in a userform listbox. I've manage to use VBA to add selected column data into the listbox. My problem is I have no idea how to create a list header on top of the list box. I try using the additem but it doesn't work.

    My listbox has horizontal scrollbar as the list is too long so I can't use label to create the list header name

    Please help...

  2. #2
    Bob Phillips
    Guest

    Re: Add Listbox header using VBA

    AFAIK you can't, you can only get headers if you bind the listbox to a
    range.

    In the ListBox,
    - set the ColumnCount property to number of columns,
    - set ColumnHeads to True,
    - set RowSource to the range of cells >>below<< the column headers text

    The cells above this RowSource range will be used as column headers.

    You can set the rowsource in VBA

    With Me.ListBox1
    .RowSource = Range("A2:A5").Address
    End With


    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "shirley_kee" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > I have Column A to BH in my excel sheet. I want to display column A, B
    > ,C,E, G and BH in a userform listbox. I've manage to use VBA to add
    > selected column data into the listbox. My problem is I have no idea how
    > to create a list header on top of the list box. I try using the additem
    > but it doesn't work.
    >
    > My listbox has horizontal scrollbar as the list is too long so I can't
    > use label to create the list header name
    >
    > Please help...
    >
    >
    > --
    > shirley_kee
    > ------------------------------------------------------------------------
    > shirley_kee's Profile:

    http://www.excelforum.com/member.php...o&userid=30384
    > View this thread: http://www.excelforum.com/showthread...hreadid=556357
    >




  3. #3
    Registered User
    Join Date
    05-05-2009
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: Add Listbox header using VBA

    If you set the rowsource, are you still able to manually modify the data in the listbox via VBA code? When I try that I get an error, stating "permission denied". This seems logical to me: I linked the listbox values up with a range of cells, so I shouldn't be able to modify otherwise. But is there a way around this?

    The only reason that I am even considering using the rowsource technique is to allow me to use the header row, but I have to be able to modify the values otherwise.
    Last edited by gtmeloney; 07-21-2009 at 06:49 PM.

  4. #4
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Add Listbox header using VBA

    hi gtmeloney,

    Did you realise that the last message in this thread was posted in June of 2006?

    The thread is probably too old for the previous posters to even remember, let alone respond to, so I suggest opening a new thread (as per the Forum rules) with your question about potential work-arounds.


    hth
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  5. #5
    Registered User
    Join Date
    05-05-2009
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: Add Listbox header using VBA

    Sorry Rob,

    I didn't know that I was breaking the rules. I have decided that its not worth my time to find a workaround, I'll just use a hidden worksheet. Sorry for the trouble.

    Greg

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Add Listbox header using VBA

    Just for the record, the short answer is: no, you can't. If you bind, you can't change; if you don't (my preference), you can't use the ColumnHeaders.
    Remember what the dormouse said
    Feed your head

  7. #7
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Add Listbox header using VBA

    Good as gold, Greg - Romper' seems to have the facts for you so it sounds like mission accomplished

  8. #8
    Registered User
    Join Date
    12-10-2010
    Location
    California
    MS-Off Ver
    Excel all versions from 5.0 (1993) to 365
    Posts
    38

    Re: Add Listbox header using VBA

    Quote Originally Posted by broro183 View Post
    Did you realise that the last message in this thread was posted in June of 2006?
    did you realize this is still relevant?
    did you realize forum threads are not just for the OP?
    i came here because it is relevant to my work. the technologies involved are still in-use.

  9. #9
    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,913

    Re: Add Listbox header using VBA

    You missed Rob's point (which you left out of your quote).

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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