Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Dynamicly Fill Listbox with column headers?

  1. #1
    Board Regular
    Join Date
    Mar 2009
    Location
    Salem, OR
    Posts
    116
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Dynamicly Fill Listbox with column headers?

    Hello,

    I am trying to fill a listbox on a userform with column headers, but I want it to be dynamic so that no matter how many column headers there are it won't be hard coded to a particular range.

    Any help or suggestions would be greatly appreciated!

    Andy

  2. #2
    Board Regular crimson_b1ade's Avatar
    Join Date
    Sep 2008
    Location
    Yonkers, New York
    Posts
    1,557
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Dynamicly Fill Listbox with column headers?

    this goes in the code for the userform. if you are using the first row as column heads then just change columnheads to false in the below code.


    Code:
     
    Private Sub UserForm_Initialize()
     
    Dim c As Long, r As Long
     
    c = Cells(1, Columns.Count).End(xlToLeft).Column
    r = Cells(Rows.Count, 1).End(xlUp).Row
    
    With ListBox1
       .ColumnCount = c
       .ColumnHeads = True
       .RowSource = "Sheet1!A1:" & Cells(r, c).Address
    End With
     
    End Sub
    You may not know the secrets of the Universe but there is one thing you should know. Everyone born in and of this Earth knows not more to such matters than you and possesses no more clairvoyance or holiness than you. So if you ought to believe in something…believe in YOURSELF!

  3. #3
    Board Regular
    Join Date
    Mar 2009
    Location
    Salem, OR
    Posts
    116
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up Re: Dynamicly Fill Listbox with column headers?

    That works great! Thanks!

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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