+ Reply to Thread
Results 1 to 10 of 10

Code to reset combobox dependant on another combobox

  1. #1
    Registered User
    Join Date
    07-28-2010
    Location
    london, england
    MS-Off Ver
    Excel 2007
    Posts
    91

    Code to reset combobox dependant on another combobox

    I have a sheet which has two comboboxes using vlookups to return populations from a reference sheet. I am looking for a code which will link them so that when a value is selected in the first, other will automatically reset to the option none and vice versa. That might not make much sense so I have attached a sample worksheet....

    On the same sheet I have also created a textbox where I want people to be able to enter their own population sizes. Here I'm looking for a code to display the value which the user types in this box in cell I11. I would also like this box to be linked to the other 2 so that they return to none when a value is entered here. Any help with these codes would be greatly appreciated...

    Thanks,
    James
    Attached Files Attached Files
    Last edited by j.farr3ll; 09-08-2011 at 09:00 AM.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Code to reset combobox dependant on another combobox

    Hi j.farr3ll

    Try this code in worksheet "Target population" module
    Please Login or Register  to view this content.
    Let me know of issues.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    07-28-2010
    Location
    london, england
    MS-Off Ver
    Excel 2007
    Posts
    91

    Re: Code to reset combobox dependant on another combobox

    Thats perfect, thanks John

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Code to reset combobox dependant on another combobox

    Hi j.farr3ll
    You're welcome...glad to be of help.

  5. #5
    Registered User
    Join Date
    07-28-2010
    Location
    london, england
    MS-Off Ver
    Excel 2007
    Posts
    91

    Re: Code to reset combobox dependant on another combobox

    Quote Originally Posted by jaslake View Post
    Hi j.farr3ll
    You're welcome...glad to be of help.
    Hi John,

    The code works great, but when I go to close the workbook I get a VBA error: Run-Time error '91' (object variable or With Block variable not set).

    If I click debug the following line of code is highlighted:

    Please Login or Register  to view this content.
    I have tried defining the variables using Dim, but this hasn't solved the problem. Do you know how to fix the error at all?

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Code to reset combobox dependant on another combobox

    Hi j.farr3ll

    This appears to be a common problem and appears to be an Excel bug. This code will work around the issue.

    In a General Module, at the very top line
    Please Login or Register  to view this content.
    In the This Workbook Module
    Please Login or Register  to view this content.
    Your Target Worksheet Module
    Please Login or Register  to view this content.
    Let me know of issues.

  7. #7
    Registered User
    Join Date
    07-28-2010
    Location
    london, england
    MS-Off Ver
    Excel 2007
    Posts
    91

    Re: Code to reset combobox dependant on another combobox

    I have tried to use this code as you describe but am now getting a 'compile error: variable not defined' when I try to use the comboboxes. This is happening on the following line:

    Please Login or Register  to view this content.
    Any Ideas?

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Code to reset combobox dependant on another combobox

    Hi j.farr3ll

    That would indicate that "bFlag" has not been defined. Have you done this
    In a General Module, at the very top line
    Please Login or Register  to view this content.
    If you have...were you using bFlag previously...show me the code in the General Module.

  9. #9
    Registered User
    Join Date
    07-28-2010
    Location
    london, england
    MS-Off Ver
    Excel 2007
    Posts
    91

    Re: Code to reset combobox dependant on another combobox

    Hi John,

    Yes I hadn't correctly entered that line in a general module.

    It is working perfectly now; no errors at all.

    Thank you very much for your help,
    James

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Code to reset combobox dependant on another combobox

    Hi James

    You're welcome...glad I could be of help. If that satisfies your need, I'd appreciate it if you'll please mark your thread as "Solved".
    To mark your thread solved do the following:
    - Go to your first post on the thread
    - Click edit
    - Click Advance
    - Just below the word "Title:" you will see a dropdown with the word No prefix.
    - Change to Solved
    - Click Save

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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