+ Reply to Thread
Results 1 to 4 of 4

How to visually unselect an item in a single selection ListBox?

  1. #1
    Registered User
    Join Date
    07-29-2019
    Location
    NC, USA
    MS-Off Ver
    365 64bit
    Posts
    47

    How to visually unselect an item in a single selection ListBox?

    I am using the first listitem in a ListBox to serve as a header row in a multicolumn ListBox but I can't seem to visually unselect it when the user selects it (since it's not actually an item I want to be selectable).

    I have the change event set to this (have attempted multiple ways to unselect as you can see)

    Please Login or Register  to view this content.
    The ingredientsbox.ListIndex correctly changes but the row is still visibly selected. Is there a way to make the selection visually go away? Thanks

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: How to visually unselect an item in a single selection ListBox?

    your code does not tell us what method you are using to load your listbox.
    put your header names in a label above the listbox.
    otherwise if listbox.listindex =0 then exit sub
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

  3. #3
    Registered User
    Join Date
    07-29-2019
    Location
    NC, USA
    MS-Off Ver
    365 64bit
    Posts
    47

    Re: How to visually unselect an item in a single selection ListBox?

    Items are added like this through a loop:

    ingredientsList.AddItem
    ingredientsList.List(ingredientsList.ListCount - 1, columnNumber) = valueStr

    Headers are added at the end the same way with index of 0.

  4. #4
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: How to visually unselect an item in a single selection ListBox?

    attached file is a demo of userform with listbox with headers.
    rowsource loading is the only method that supports the use of headers.
    however it is the least stable (if you use the 'rowsource' within the properties section)
    by the far better way is to use the .list method and load from a table via an array and put a label containing your headers over the top of the listbox.
    the .additem is really intended for loading just individual items, it is an inefficient way of loading multiple items.
    Attached Files Attached Files

+ 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. Save Listbox Selection of sheets as single PDF
    By adamjhodson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-09-2019, 05:14 PM
  2. a VBA Code that will copy and paste a Row upon selection of an item in a Listbox
    By taffboyo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-27-2016, 05:24 PM
  3. [SOLVED] Vba with changing cell value in sheet based on ListBox item selection - Challenging
    By sintek in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-29-2016, 08:48 AM
  4. Show dynamic data depending on selection of item from listbox.
    By MOHAMMESALMAN in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-02-2015, 02:21 AM
  5. [SOLVED] listbox item selection to got to specific sheet
    By sumonrezadu in forum Excel General
    Replies: 14
    Last Post: 05-17-2013, 12:38 AM
  6. 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
  7. Unselect from UserForm ListBox
    By bstubbs in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-18-2009, 05:59 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