Results 1 to 5 of 5

Thread: Listbox Simple Question

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2003
    Location
    Mt. Holly, NJ
    Posts
    31

    Listbox Simple Question

    Hi all,

    OK, I have a macro that opens a new worksheet in Excel. That worksheet has a listbox called lstBank. I want to get the value in lstbank. No matter what I try, i can't seem to find out how to do something as simple as put a msgbox up with the highlighted member of the list in it.

    msgbox lstbox

    only returns a null string.

    I can't seem to find the answer anywhere on the net, and i know this should be the easiest thing in the world.

    Thanks,
    Joshua Wise

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    msgbox ltsbox.Text ?


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2003
    Location
    Mt. Holly, NJ
    Posts
    31
    lstbank.text only gives me the error message "Object Required"

    I know I have the name right on the control, but I'm not sure how to reference it. I'm using Excel 97.

    Thanks,
    Joshua

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2003
    Location
    Mt. Holly, NJ
    Posts
    31
    OK, I got my reference to work for lstbox.text, however, now I need to know if there is a way to pull the data that is visible, not just selected. I have a list box that only shows one piece of data at a time. Is there a way to pull the VISIBLE data instead of the SELECTED data?


    Thanks,
    Joshua Wise

  5. #5
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    If it only shows one item at a time, the visible item will always be the top item. You can use the TopIndex property to get the index value of this item and then return the text of that index item in the list.

    VB Code:
    1. MsgBox lstBank.List(lstBank.TopIndex)
    To always select the visible item, on the click event set the ListIndex equal to the TopIndex.

Posting Permissions

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



Click Here to Expand Forum to Full Width