+ Reply to Thread
Results 1 to 9 of 9

Deselect a Listbox

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-19-2015
    Location
    Karnataka, INdia
    MS-Off Ver
    MS Office 2010
    Posts
    277

    Deselect a Listbox

    Hello,

    Is there anyway to deselect a value in Listbox4 when clicked twice?

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Deselect a Listbox

    Try something like this....

    Change ListBox1 in the following code as per the name of your ListBox.
    Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    Dim i As Long
    For i = 0 To ListBox1.ListCount - 1
       ListBox1.Selected(i) = False
    Next i
    End Sub
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Forum Contributor
    Join Date
    05-19-2015
    Location
    Karnataka, INdia
    MS-Off Ver
    MS Office 2010
    Posts
    277

    Re: Deselect a Listbox

    Thanks you for the code, I tried but not working in Form Control.

  4. #4
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Deselect a Listbox

    What is the Name of your ListBox Control?

  5. #5
    Forum Contributor
    Join Date
    05-19-2015
    Location
    Karnataka, INdia
    MS-Off Ver
    MS Office 2010
    Posts
    277

    Re: Deselect a Listbox

    It is List Box 4.

  6. #6
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Deselect a Listbox

    Then try this. The code below will deselect all the selected items in the ListBox4 after double clicking the listbox.

    Private Sub ListBox4_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    Dim i As Long
    For i = 0 To ListBox1.ListCount - 1
       ListBox1.Selected(i) = False
    Next i
    End Sub

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Deselect a Listbox

    For a listbox from the Forms menu, assign it to this macro
    Sub ListBox1_Change()
        Static flag As Boolean
        If flag Then
            ActiveSheet.Shapes(Application.Caller).OLEFormat.Object.ListIndex = 0
        End If
        flag = Not flag
    End Sub
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  8. #8
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Deselect a Listbox

    Ah I missed that it was a form control though the OP mentioned that. My bad.

  9. #9
    Forum Contributor
    Join Date
    05-19-2015
    Location
    Karnataka, INdia
    MS-Off Ver
    MS Office 2010
    Posts
    277

    Re: Deselect a Listbox

    That Worked Perfect! Thanks Both of you.

+ 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. [SOLVED] code to deselect if empty record is clicked in listbox
    By adelkam in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-26-2015, 02:07 PM
  2. [SOLVED] if anything in listbox select first item, if listbox empty do nothing (listbox in userform
    By mcdermott2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-17-2015, 12:49 PM
  3. [SOLVED] Listbox Automatic Deselect Bug
    By cmore in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-05-2013, 07:36 PM
  4. Listbox to Listbox, no duplicates & submitting same UserForm data for each Listbox entry.
    By jamieswift1977 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-18-2012, 12:18 PM
  5. How do I deselect an item from a ListBox
    By skysurfer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-27-2010, 10:59 AM
  6. [SOLVED] ActiveChart.Deselect won't Deselect
    By Mark Stephens in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 06-15-2005, 10:05 PM
  7. deselect
    By sali in forum Excel General
    Replies: 2
    Last Post: 04-30-2005, 06:06 PM

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