+ Reply to Thread
Results 1 to 8 of 8

Auto select first item in listbox

  1. #1
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Auto select first item in listbox

    How can I set a ListBox to autoselect the first item. I tried the following code on the user form Initialize procedure:
    Please Login or Register  to view this content.
    Which comes after the following code to pollute the list box:
    Please Login or Register  to view this content.
    But I'm getting a Compile Error.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Auto select first item in listbox

    Hello Nitefox,

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Auto select first item in listbox

    Hi Leith,
    That code generates run-time error 380, could not set ListIndex property. Invalid property value.

  4. #4
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Auto select first item in listbox

    try this,

    Please Login or Register  to view this content.
    Happy Computing ,

    Xlbiznes.

    To show your appreciation please click *

  5. #5
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Auto select first item in listbox

    That gave me the same error.
    Could it be due to the code I'm running before it in the same event? This is all the code:
    Please Login or Register  to view this content.
    I have attached the workbook also. The user form is called NewItemMultiple.
    Attached Files Attached Files

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

    Re: Auto select first item in listbox

    The code to select the first item should go after the Next.
    If posting code please use code tags, see here.

  7. #7
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Auto select first item in listbox

    Checked you code.

    put the listbox item select after the for loop, like this.

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Auto select first item in listbox

    Silly me. Thank you, that fixed it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Multi select Listbox Items selection based on other Listbox item selection.
    By srinivassathi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-20-2011, 05:53 AM
  2. How to select a default item in the VB ListBox?
    By qed59 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-22-2010, 01:16 AM
  3. Select item in listbox via macro
    By Rick_Stanich in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-12-2010, 04:18 PM
  4. ListBox item select default
    By matrixknow in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-12-2007, 08:21 AM
  5. select listbox item automatically
    By ilyaskazi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-14-2005, 07:27 AM

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