+ Reply to Thread
Results 1 to 6 of 6

Add items to second column of Listbox

  1. #1
    Forum Contributor
    Join Date
    03-21-2004
    Location
    Norwich, CT USA
    MS-Off Ver
    Excel 2010
    Posts
    163

    Add items to second column of Listbox

    I use the following code to fill a single column, user form, listbox:

    Please Login or Register  to view this content.
    This code is located in the form module and called from the form initialization sub.
    lst_Empl is the listbox name
    emplRng is a public range variable. It gets set in the initialize sub to a a named range that dynamically spans some of row 2. currently C2-S2.


    This code works just fine.

    I want to add a second column to the listbox to help the user narrow down their selections. the second column data comes from row 3 otherwise the same as the first range.

    I have created a new named range, public range variable, tmp variable and set the range variable appropriately in the parent sub. All new stuff has "Psn" in the names.
    also in the properties columncount is set to 2
    Please Login or Register  to view this content.
    When I run this the second set of data just fills in beneath the first. I realized I have not directed the second set of data to the second column.
    and reading through the references I cant figure out how to differentiate between the two columns when filling them.

    Any help will be appreciated
    Thanks
    Robert

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Add items to second column of Listbox

    Robert

    It's not really clear what you want to go in the 2nd column and how it relates to the 1st column.

    Is the range for the 2nd column an offset of the range for the 1st?

    Generally to refer to the 2nd column of a listbox you can use List(idx, 1), where idx is the row.

    If there was an offset then this might work.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    03-21-2004
    Location
    Norwich, CT USA
    MS-Off Ver
    Excel 2010
    Posts
    163

    Re: Add items to second column of Listbox

    Norie, sorry that was unclear. The 1st column in the listbox is fed from row 2 and the second column is from row 3. So yes offset by one row.
    At a glance what you provided makes sense. I will work with it tonight.
    Thanks very much!
    Robert

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Add items to second column of Listbox

    Robert

    The code I posted will populate the first column from range emplRng and the second column from the row below that.

    So if emplRng is row 2 the second column will be populated from row 3.

  5. #5
    Forum Contributor
    Join Date
    03-21-2004
    Location
    Norwich, CT USA
    MS-Off Ver
    Excel 2010
    Posts
    163

    Re: Add items to second column of Listbox

    Norie, the code work perfect just as it was. Thanks

  6. #6
    Forum Contributor
    Join Date
    03-21-2004
    Location
    Norwich, CT USA
    MS-Off Ver
    Excel 2010
    Posts
    163

    Re: Add items to second column of Listbox

    When I try to add to your reputation, I'm getting the message: " You must spread some Reputation around before giving it to Norie again."
    Although I'm sure I did not add this thread to your reputation yet.

+ 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