+ Reply to Thread
Results 1 to 4 of 4

Enable Command Button if ANY of 4 Listboxes Have a Selection Made

  1. #1
    Registered User
    Join Date
    07-15-2013
    Location
    Arizona
    MS-Off Ver
    Excel 2016
    Posts
    64

    Enable Command Button if ANY of 4 Listboxes Have a Selection Made

    Hello Forum and thanks in advance.

    I have a fairly straightforward UserForm with 4 listboxes and 4 option textboxes (the textboxes do not need to be a part of the validation I'm needing). I then have a command button that I want to be enabled ONLY if ANY of the 4 Listboxes have a selection. I've tried the "Change" event code below and it works upon the first selection of any listbox item. However, if the user de-selects all selections in the listboxes (i.e. they are all unchecked), the command button remains enabled. I need the validation logic to enable/disable the button to persist as long as the user has the form open and if there is not a selection in ANY of the listboxes. The reason being is that if they click the command button it will update the cells in the worksheet, which if empty may overwrite previous work completed with blank cells.

    I'm not necessarily tied to this approach, so other ideas are welcome. Your collective expertise and input is greatly appreciated!

    Thanks,
    Chris

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor gsnidow's Avatar
    Join Date
    07-22-2010
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    150

    Re: Enable Command Button if ANY of 4 Listboxes Have a Selection Made

    Chris, here is a sort of brutish way to accomplish what you need. You are basically counting the selected items. My machine is updating laboriously right now, so I can't get Excel to open, so it's generic. You would have to count the items in each list box.

    Please Login or Register  to view this content.
    Greg
    Just a guy trying to make work stuff easier.

  3. #3
    Registered User
    Join Date
    07-15-2013
    Location
    Arizona
    MS-Off Ver
    Excel 2016
    Posts
    64

    Re: Enable Command Button if ANY of 4 Listboxes Have a Selection Made

    Thanks for the quick reply Greg, but I run into a different variation of the same problem, which I believe exists with using the Change event for the listboxes. Your code works for each listbox in the Frame they reside in (maybe the Frame setup is an important detail I left out), but now if I make a selection in the first listbox and then a selection in the second listbox, the button disables again if I go back and deselect my choice in the first listbox because the change event for that listbox is superceding the event for the second listbox since it appears first in the code. That's how I'm understanding the issue.

    Is there a way to code to count the items for ALL listboxes in the frame together or for any value in the frame itself and then apply the enable/disable if/then logic?

    Thanks again,
    Chris

    Here's what I used that's creating the problem described above (only did it for 2 of the 4 listboxes):
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    07-15-2013
    Location
    Arizona
    MS-Off Ver
    Excel 2016
    Posts
    64

    Re: Enable Command Button if ANY of 4 Listboxes Have a Selection Made

    Deleting duplicate post

+ 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. How to change selection in two listboxes by changing selection in a third listbox
    By GIS2013 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-01-2013, 02:39 PM
  2. [SOLVED] Enable/Disable Command Button
    By rain4uu in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-06-2012, 03:27 AM
  3. Enable/disable button from list selection
    By Matt75 in forum Excel General
    Replies: 2
    Last Post: 08-14-2010, 10:40 PM
  4. Command button Enable using VBA
    By psatkar in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-10-2006, 05:50 AM
  5. Enable Command Button 1 & 2
    By Mikeice in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-17-2005, 01:01 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