+ Reply to Thread
Results 1 to 4 of 4

Select one item from a listbox disables another listbox

Hybrid View

EagleInsight Select one item from a... 01-20-2014, 11:05 PM
AlphaFrog Re: Select one item from a... 01-21-2014, 01:28 AM
EagleInsight Re: Select one item from a... 01-22-2014, 08:08 PM
AlphaFrog Re: Select one item from a... 01-22-2014, 09:53 PM
  1. #1
    Registered User
    Join Date
    01-09-2014
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    15

    Select one item from a listbox disables another listbox

    I have two listboxes that both have a different set of names. Can anyone help me with VBA coding that will disable a user from clicking an item in one listbox if an item has already selected an item in another listbox - on the same Userform.

    Thanks,
    Last edited by EagleInsight; 01-22-2014 at 07:58 PM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Select one item from a listbox disables another listbox

    Try something like this...


    Private Sub ListBox1_Click()
       ListBox2.Enabled = ListBox1.ListIndex = -1
    End Sub
        
    Private Sub ListBox2_Click()
        ListBox1.Enabled = ListBox2.ListIndex = -1
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    01-09-2014
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Select one item from a listbox disables another listbox

    Thanks alphafrog. It works in preventing me clicking on the other userform. However i also have a Clear selection button on the same userform using the below code:

    Private Sub CommandButton1_Click()
    UserForm1.ListBox1.ListIndex = -1
    End sub

    Private Sub CommandButton2_Click()
    UserForm1.ListBox2.ListIndex = -1
    End sub

    What is now happening is once i select an item in one listbox and then clear it, i am disabled from clicking on the other listbox. Any advice?

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Select one item from a listbox disables another listbox

    When you clear a ListBox, enable the other as well.

    Private Sub CommandButton1_Click()
    UserForm1.ListBox1.ListIndex = -1
    UserForm1.ListBox2.Enabled = True
    End Sub
        
    Private Sub CommandButton2_Click()
    UserForm1.ListBox2.ListIndex = -1
    UserForm1.ListBox1.Enabled = True
    End Sub
    Last edited by AlphaFrog; 01-22-2014 at 09:56 PM.

+ 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] Auto select first item in listbox
    By Nitefox in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 7
    Last Post: 12-26-2013, 05:04 AM
  2. Select listbox item then appear textbox
    By sohaila in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-01-2013, 04:41 AM
  3. 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
  4. 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
  5. select listbox item automatically
    By ilyaskazi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-14-2005, 07:27 AM

Tags for this Thread

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