+ Reply to Thread
Results 1 to 27 of 27

VBA: Making ComboBox Open on Selection

  1. #1
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    VBA: Making ComboBox Open on Selection

    Good morning, all!

    I've successfully managed to deploy the script below (from the Contextures site) in my workbook, and it works beautifully, but I was wondering if it is possible to add two small tweaks:

    1. Ideally, instead of having to double click the cell containing the validation list to make the combobox appear, I'd like to single click. Having Googled a bit first, I am not sure if this is possible, but thought I'd ask.
    2. When the combobox is selected, I'd like it to drop down automatically, revealing the list.

    Here's the code (slightly adapted from the original to make it work in my workbook):

    Please Login or Register  to view this content.
    I'm attaching the sample workbook from the Contextures site, as mine contains sensitive data. Thank you for any advice.
    Attached Files Attached Files
    Last edited by AliGW; 05-19-2019 at 04:23 AM.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA: Making ComboBox Open on Selection

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: VBA: Making ComboBox Open on Selection

    Thanks. I will try to understand what you are telling me and implement it!

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: VBA: Making ComboBox Open on Selection

    Ali, I think this is easier:

    Please Login or Register  to view this content.
    I'm no friend of the SendKeys but this is probably the only way to get it to work, no combobox, just the validation list
    I've attached my version of you sample file
    Attached Files Attached Files
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: VBA: Making ComboBox Open on Selection

    Thanks, gents. Unless I'm missing the obvious, neither does what I thought I'd asked! They both open the validation list, not the overlying combobox. It's the combobox that I want to open when the user clicks on the cell.

    I need to use the combobox because I want the list to change as the user types into the box.

    If what I've asked isn't possible, it's no big deal.

  6. #6
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA: Making ComboBox Open on Selection

    Please Login or Register  to view this content.

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: VBA: Making ComboBox Open on Selection

    Thanks, but just providing code without any explanation I am afraid is not great for me - I am no expert. When you provide code, perhaps you wouldn't mind just adding a line or two about what you've changed and why? I do want to learn as I go along. Thanks.

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: VBA: Making ComboBox Open on Selection

    No, sorry - I have looked at the latest code in post #6 and can't work out where it should go and what in the old code I should take out. Sorry, but I'm just not proficient enough to be able to use what you have given me without some instructions.

  9. #9
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA: Making ComboBox Open on Selection

    This code replaces both your Selection Change and Your DoubleClick event code.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by mehmetcik; 05-19-2019 at 08:38 AM.

  10. #10
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: VBA: Making ComboBox Open on Selection

    Hi Ali,

    Towards your first question.. of when and where to show the combobox. This is down to the event macro you pick basicly there are 3 choices.

    Worksheet_SelectionChange - This event macro is triggered by selecting a (different) cell
    Worksheet_BeforeDoubleClick - This event macro will gets triggered by double clicking your mouse
    Worksheet_BeforeRightClick - This event macro will gets triggered by right-clicking your mouse.

    So depending on when you want the combobox to show, you can pick any of the three events

    all you need to do is copy over the entire code from BeforeDoubleClick event to the SelectionChange event. And remove (or comment) out the ling that says Cancel = True because selection change does not have that preset. (Cancel = true is used in before double click to suppress the cell edit mode and in the rightclick event to prevent the menu from showing)
    Please Login or Register  to view this content.
    I saw you had some of the code already in selection change but it was missing some parts where the validation list is linked to it so there are values to show. But when you move the whole code then it works as intended. I attached the example with the working code. but basicly I did nothing else than copy paste the code to the selection event (and disable the cancel line)

    For your second question, I do not know of any setting that can do that. but that might be my lack of knowledge although I think it does not exist as comboboxes are intended to be fixed on the sheet or a userform and have the arrow to indicate you can show a dropdownlist.
    Attached Files Attached Files

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: VBA: Making ComboBox Open on Selection

    Thank you both. I've been gardening, but will look again at this later today. I will let you know whether or not I manage to work it out! Thanks for the added information.

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: VBA: Making ComboBox Open on Selection

    Hi, Roel!

    Towards your first question. of when and where to show the combobox.
    Neither of my questions was about this, actually - sorry you got that impression. The combobox already appears where and when I want it to.

    I will have a look at your workbook and see if it addresses the issues. I am afraid that Mehmetcik's doesn't appear to.

    EDIT: OK - yours addresses the issue of the combobox appearing with just one click instead of having to double click - thank you. Is it possible to get the combobox to drop down (open) as soon as we click? I have seen combobox.dropdown online, but don't know where I would need to put this in the code.
    Last edited by AliGW; 05-19-2019 at 10:31 AM.

  13. #13
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: VBA: Making ComboBox Open on Selection

    I've just one more thing that I'd like to be able to do here if possible. Can I get one cell (A31) always to show whatever is currently in the combobox whenever it is active and being typed into?

  14. #14
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: VBA: Making ComboBox Open on Selection

    Ah, cool I did not know that .Dropdown
    It is realtive simple to use. the combobox you use is named TempCombo and that name can also be used to handle the combobox settings. so the proper code is


    TempCombo.Dropdown

    I placed it after the combobox codeline where the shape is activated.
    the cboTemp name that is given is part of the shape-objects and that type of object does not allow dropdown. so that cannot be used to handle the dropdown showing

    Please Login or Register  to view this content.

  15. #15
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: VBA: Making ComboBox Open on Selection

    The drop-down works, however the range statement doesn't make anything appear in A31.

    Another side effect now is that I cannot hit enter or tab to move out of the combobox.

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: VBA: Making ComboBox Open on Selection

    I have resolved the tabbing issue - I had accidentally introduced a typo in the sub in question, but that is now fixed.

    I have decided not to bother with the mirroring of the combobox value in A31 for now.

    Thanks again for all the help!

  17. #17
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: VBA: Making ComboBox Open on Selection

    Sorry - one further question. Is there a way to limit the appearance of the combobox to certain rows in the worksheet? Specifically rows 3 to 24. In other words, I only want the combobox to appear over data validation cells within those specific rows.

  18. #18
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: VBA: Making ComboBox Open on Selection

    You can limit it using the target intersect like I used in my idea several post back

    Please Login or Register  to view this content.
    Last edited by Keebellah; 05-20-2019 at 02:18 AM. Reason: code

  19. #19
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: VBA: Making ComboBox Open on Selection

    I'm sorry - I have looked at the code in your earlier workbook, and you said that was for a solution without the combobox, which I don't want.

    Where in the current code below should I add your new code snippet, please?

    Please Login or Register  to view this content.

  20. #20
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: VBA: Making ComboBox Open on Selection

    My answer was to give you the idea how to make something happen in a desired region using the Intersect.

    The code you pasted, from which file is that?

  21. #21
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: VBA: Making ComboBox Open on Selection

    The code is from the workbook I am using (that I cannot share), but that is based on the code in the workbook I shared in the opening post.

    Where in my code (or the code in the workbook in my opening post, if you prefer) would I need to add the code you have suggested in post #18, please?

  22. #22
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: VBA: Making ComboBox Open on Selection

    Let me get back to you later, I'm late and have to go now.
    I've also got some suggestions but let me think them over.

  23. #23
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: VBA: Making ComboBox Open on Selection

    OK. I'm at work now, so will look in later.

  24. #24
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: VBA: Making ComboBox Open on Selection

    In the current SelectionChange event code there is a line that makes sure that this combobox only appears on cells with a Data validation of the list type
    this is the codeline that does that (it is about halfway down the event code, just above the 'cancel=true disabled in my last post)
    Please Login or Register  to view this content.
    That means that on every cell on that worksheet with a Data validation of the type list the JuniorsCombo-box will appear.
    If you only want to show it in a certain range of cells then you can add a line (or replace the current line with)


    Based on the range B2:C11 in your example sheet you can add the following to the current line
    Please Login or Register  to view this content.
    this will limit the combobox to appear only in that cells if they have a cell validation list. I kept this part in to make sure that if in your real sheet there are blank cells or cells to fill without a datavalidationlist the box will not appear.
    offcourse you will need to change the range of cells to fit your needs in the original sheet.

  25. #25
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: VBA: Making ComboBox Open on Selection

    Perfect, Roel - thank you once again. It's so simple when you know how (which, evidently, I don't). My workbook now works flawlessly.

    Thanks again to all respondents.

  26. #26
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: VBA: Making ComboBox Open on Selection

    Glad to have helped out and thanks for the rep.

  27. #27
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: VBA: Making ComboBox Open on Selection

    I was called away and wasn't able to help out and just see that it's solved, but still I'd like to share this one.
    You see, I'm not really a fan of ActiveX elements even if you can do nice things with them.
    What I did is have a validation list in the worksheet ValidationLists and in sheet 1 in Column A1-A100 cells with data validation for the list in the other sheet.
    I was playing around and needed code to append n a missing item to an existing validation list and thus this one.
    Two ways, enter a value in E3 and if it it not present in the list it will be added, the list sorted and the data validation in A1-A100 updated.
    Or you can double click a cell in column A (with the data validation) and enter a new value in the input box,

    This was just for fun but maybe it can be put to good use
    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. ComboBox values source being changed based on another combobox selection in a UserForm
    By stephenanderson in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-08-2016, 11:12 PM
  2. [SOLVED] Code required to Auto Populate 3rd Combobox based on 02nd Combobox Selection
    By bimmy80 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-14-2015, 03:56 AM
  3. [SOLVED] Using Command Button to Open Worksheet Based on ComboBox Selection
    By laura_jean in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-10-2014, 09:23 AM
  4. Making a FormControl ComboBox's list depend on the value of another ComboBox's Reference
    By dpsciarrino in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-24-2013, 11:52 PM
  5. [SOLVED] fill combobox selection based on a selection from the first combobox
    By Monza in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-14-2013, 07:34 PM
  6. [SOLVED] Reset ComboBox After Making A Selection
    By Liz3nz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-08-2013, 02:14 PM
  7. Open workbook based on combobox selection
    By krjoshi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-19-2012, 11:50 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