+ Reply to Thread
Results 1 to 16 of 16

VBA to hide multiple combo boxes

  1. #1
    Registered User
    Join Date
    11-09-2016
    Location
    UK
    MS-Off Ver
    365
    Posts
    85

    VBA to hide multiple combo boxes

    Hi all,

    I have a worksheet containing multiple combo boxes, many but not all of which i want to hide on opening (only to be revealed subject to selections in other visible combo boxes as user completes form). The combo boxes are non-contiguous.

    I previously used this code:

    Please Login or Register  to view this content.
    etc etc

    but this is repetitive and slow so i'm hoping there is a better way?

    any help much appreciated

    Thanks

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: VBA to hide multiple combo boxes

    You can use an array:

    Please Login or Register  to view this content.
    Rory

  3. #3
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: VBA to hide multiple combo boxes

    If you know the index # of the dropdowns that you want to hide...

    Something like...
    Please Login or Register  to view this content.
    To find out index# of each dropdown...
    Please Login or Register  to view this content.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  4. #4
    Registered User
    Join Date
    11-09-2016
    Location
    UK
    MS-Off Ver
    365
    Posts
    85

    Re: VBA to hide multiple combo boxes

    Thanks both!

    CK76 i have used your code and it appears to be working perfectly but i'm getting na error message "unable to set the visible property of DropDown", but it appears to have worked? any ideas>?
    thanks again

  5. #5
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: VBA to hide multiple combo boxes

    Hmm, I'm not sure. You may have Index# that's larger than any existing dropdown.

    And you are welcome

  6. #6
    Registered User
    Join Date
    11-09-2016
    Location
    UK
    MS-Off Ver
    365
    Posts
    85

    Re: VBA to hide multiple combo boxes

    can anyone help with this?

    the macro is working in that it is hiding and unhiding the correct drop down boxes but then its throwing up this error message "unable to set the visible property of DropDown"?

  7. #7
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: VBA to hide multiple combo boxes

    Without sample of where this is occurring. Bit hard to help. As we'll need to guess at what exactly is going on.

    If you did verify that the .DropDowns(index#) exist in worksheet. Then it's likely due to some setting. But we are not mind reader after all

    To upload workbook, use "Go Advanced" button and follow "Manage Attachments" hyperlink. It will launch new tab/window for managing uploads.

  8. #8
    Registered User
    Join Date
    11-09-2016
    Location
    UK
    MS-Off Ver
    365
    Posts
    85

    Re: VBA to hide multiple combo boxes

    I can't really upload the file as its sensitive and to strip it all out wouldn't leave much - I just tried the code on another workbook with no content and it works fine, so its not the code it must be something else to do with my workbook... its not protected. anything else I can look for? thanks again

  9. #9
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: VBA to hide multiple combo boxes

    Can't you remove all the data and just leave the code and dropdowns?

  10. #10
    Registered User
    Join Date
    11-09-2016
    Location
    UK
    MS-Off Ver
    365
    Posts
    85

    Re: VBA to hide multiple combo boxes

    ok I've stripped out all the data, the second worksheet had all the details for the combo boxes but I've deleted most of it.

    the code is in the worksheet section "on open"

    thanks!
    Attached Files Attached Files

  11. #11
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: VBA to hide multiple combo boxes

    There doesn't appear to be a dropdown with index 78 on that sheet. Also, I'd recommend you loop through the array:

    Please Login or Register  to view this content.
    for example.
    Last edited by rorya; 08-08-2019 at 10:53 AM.

  12. #12
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: VBA to hide multiple combo boxes

    Looks like you've hit limit of array elements that can be used at once to set visible state.

    As well, you don't have DropDowns(78) in your workbook.

    You can either break it into chunks or just loop over it. Personally, I'd just loop over each dropdown like below. Speed isn't that much different.
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    11-09-2016
    Location
    UK
    MS-Off Ver
    365
    Posts
    85

    Re: VBA to hide multiple combo boxes

    Thanks Rorya, I've taken the 78 out and still the same issue

    I tried the code in isolation with one box at a time incase there were any issues with the box references but same issue

    the weird thing is it is giving the error message but when you click End it executes the code as expected?

  14. #14
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: VBA to hide multiple combo boxes

    You shouldn't get error if you loop (and exclude the non existent dropbox).

    See attached. I had no issue.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    11-09-2016
    Location
    UK
    MS-Off Ver
    365
    Posts
    85

    Re: VBA to hide multiple combo boxes

    Perfect! Thank you, you've saved me from endless hair pulling!

    do you know what I was doing wrong? the code worked on a different sheet...?

  16. #16
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: VBA to hide multiple combo boxes

    It's due to 1 of two things, I'd wager.

    1. Index was out of bounds for existing DropDowns in worksheet
    2. Too many array elements were accessed at once (can't find documentation on in, but you can test yourself by increasing array element one by one).

    If you are satisfied with answers provided, please mark the thread as solved by using thread tool found at top of your initial 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. [SOLVED] Using Multiple Combo Box Values to populate a cell (Excluding blank combo boxes)
    By mnadamn19 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-10-2016, 08:38 PM
  2. [SOLVED] Using Multiple Combo Box Values to populate a cell (Excluding blank combo boxes)
    By mnadamn19 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2016, 10:49 AM
  3. Using Multiple Combo Box Values to populate a cell (Excluding blank combo boxes)
    By mnadamn19 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2016, 03:45 PM
  4. I need a code for presence check to check multiple text boxes and combo boxes
    By Lee_wwfc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-24-2013, 01:53 PM
  5. How to hide combo boxes?
    By MnO in forum Excel General
    Replies: 2
    Last Post: 11-14-2008, 08:46 AM
  6. Hide my combo boxes!
    By hays4 in forum Excel General
    Replies: 6
    Last Post: 11-07-2005, 10:50 AM
  7. multiple combo boxes
    By LilyDog7 in forum Excel General
    Replies: 4
    Last Post: 10-17-2005, 05:22 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