+ Reply to Thread
Results 1 to 9 of 9

Execute Code When Selecting from a drop down

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

    Execute Code When Selecting from a drop down

    Hi all

    I am creating a form for users to fill in.

    On opening, the form will have a lot of hidden rows that only become visible if certain criteria are met

    This is mainly driven by Form Control Combo Boxes

    eg.

    Please Login or Register  to view this content.
    I want this code to run once the selection is made

    In the above example, the selection is made in Cell C56 with the cell link in D56. Once the user makes a selection in C56, if the answer is "yes" (1 on cell link) I want row 58 to become visible.

    what is the best way to do this?

    many thanks in advance!

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Execute Code When Selecting from a drop down

    Just assign that Macro you've written to the combobox

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

    Re: Execute Code When Selecting from a drop down

    Well that was pleasantly surprisingly simple! Thanks Kyle!!!

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Execute Code When Selecting from a drop down

    no problem

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

    Re: Execute Code When Selecting from a drop down

    Ok so now I need the hidden rows to be hidden on opening the workbook, only to become visible if relevant criteria selected in drop downs. Some of the hidden rows contain drop down boxes which need additional code to hide/reveal. I found this code online but it's not working. I also can't get back the drop downs I've hidden! any ideas?

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by Maleficent; 04-24-2019 at 07:31 AM.

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

    Re: Execute Code When Selecting from a drop down

    your code for Hide and Show is identical so the combobox never gets hidden..
    you need to change the hide code. .

    Please Login or Register  to view this content.
    also read up on how and when to use some elements like
    with ..end with - you use when you want to do multiple changes on 1 range or worksheet not if you only have 1 change to make
    same for declaring, setting and using variables. for only 1 time use it is pointless..

    following code does exactly the same as above
    Please Login or Register  to view this content.

    As an alternative code you can also directly link the combobox state to the row state
    Please Login or Register  to view this content.
    The outcome of Rows(58).Hidden will be true or false and thus will show or hide the combobox depending on if the row is visible.
    this way you only need 1 code to handle hiding and showing the combobox.

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

    Re: Execute Code When Selecting from a drop down

    Thanks Roel, i'll have a play around with this! I think I edited the show/hide to true/false incorrectly when I was playing around with it yesterday trying to get it back.

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

    Re: Execute Code When Selecting from a drop down

    Starting again.....

    I need to hide certain rows on opening the workbook, to only become visible if certain criteria is selected in the drop down boxes.

    I found this online:
    Please Login or Register  to view this content.
    But it doesn't work. Row 58 is visible when I open the workbook. I don't have any other code in the module at present.

    Thanks

    UPDATE - fixed it! I had it in the "general" window instead of "workbook"
    Last edited by Maleficent; 04-25-2019 at 08:15 AM.

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

    Re: Execute Code When Selecting from a drop down

    I have this working for the first part - basically the user has the option to select how many passengers they want to add. if they select 1, 1 set of fields will be unhidden, if they select 2, 2 sets of fields will be unhidden etc. But if they choose 2 and then want to change their mind and choose 1, I want the second set of fields to disappear again. what is the best way to go about this?

    Here is my code:

    Please Login or Register  to view this content.
    Last edited by Maleficent; 04-26-2019 at 07:20 AM.

+ 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] Execute data label coloring code when drop down list changed
    By Villalobos in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-20-2017, 03:52 PM
  2. code to execute a keyboard shortcut or to execute a toolbar button
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-09-2015, 12:16 PM
  3. Replies: 7
    Last Post: 08-23-2013, 10:56 AM
  4. Drop down list to execute macro
    By dagindi in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-05-2010, 05:16 PM
  5. Need to execute VBA code @ 9:30:01 exactly
    By jkupfer in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-31-2010, 01:47 PM
  6. Execute Code
    By gti_jobert in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-02-2006, 05:40 AM
  7. Code won't execute...
    By Dolemite in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-20-2005, 02:22 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