+ Reply to Thread
Results 1 to 19 of 19

Excel Code run when combox list item is selected.

  1. #1
    Registered User
    Join Date
    07-10-2013
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    12

    Excel Code run when combox list item is selected.

    I have the following code that i only want to run when specific drop down is selected from the combo list box. As now it's in Module 1 and runs at all times on the worksheet.

    I'm pretty new to excel so your help is greatly appreciated.

    Please Login or Register  to view this content.
    Last edited by Leith Ross; 07-11-2013 at 12:43 PM. Reason: Added Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Excel Code run when combox list item is selected.

    Hello cllaguno,

    Welcome to the Forum!

    What causes the macro to run at all times?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    07-10-2013
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Excel Code run when combox list item is selected.

    I guess it's not that it runs at all times it's more like adhoc changes to it have it run.

    Attached a basic version of what it does. It moves the rows with 1 in column e to another worksheet. Basis is i'm creating a survey and i only want the ones with x in them to be answered so only those get copied to worksheet. So whenever you are on the worksheet with the code it refreshes (thus constantly working). Ideally i'd i only wanted a few of the columns and rows to be copied over but that became too hard and then i only wanted this to happen when i selected specific item from the list and that's where i am now.

    Hope this is clear. sorry if it's not.
    Attached Files Attached Files

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Excel Code run when combox list item is selected.

    Hello cllaguno,

    I have changed the macro to run when any cell in column "E" on "Maryland" is changed.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    07-10-2013
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Excel Code run when combox list item is selected.

    Thanks.

    So now the question is how can associate that with an item from a combo box? I ask because i'm going to have different versions of 'Marital Statue' like Marital Status 1, Marital Status 2, and for each it will be different what name i want to select.

    You've been a lot of help.

  6. #6
    Registered User
    Join Date
    07-10-2013
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Excel Code run when combox list item is selected.

    I also received an error when i opened this

    Compile error --Invalide reference pertaining to .usedrange

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Excel Code run when combox list item is selected.

    Hello cllaguno,

    As for the problem with the UsedRange, I forgot to prefix it with ActiveSheet. the code should read...
    Please Login or Register  to view this content.
    There were no drop downs on the sheet. If you have a workbook that does then please post it.

  8. #8
    Registered User
    Join Date
    07-10-2013
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Excel Code run when combox list item is selected.

    I've attached the file with the drop down. I added the ActiveSheet but now there is an error on .Columns?

    So, i was trying to add the code to Combo box list and use case to select Private Sub Worksheet_SelectionChange(ByVal Target As Range) but don't think i was doing it right.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    07-10-2013
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Excel Code run when combox list item is selected.

    Did the above make sense?

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Excel Code run when combox list item is selected.

    Hello cllaguno,

    I am a little confused about where the selection in the drop down is supposed to go. Is it in row "E" of the active cell in the table?

  11. #11
    Registered User
    Join Date
    07-10-2013
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Excel Code run when combox list item is selected.

    Look at the updated version that is attached. I'd like it to work as it does not but with the drop down on the Sheet 1 tab. When i moved the drop down to Sheet 1 i was getting a blank screen and not what i get now when you pick the different drop downs.

    Thanks again for you help.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    07-10-2013
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Excel Code run when combox list item is selected.

    On the attached i just sent when you pick Marital Status i get everything from Maryland but only those with 1 in Column E on the Copy AllRows Filled with 1 tab ; when i pick Marital Status_1 i get everything from MAryland but only those with 1 in Column F on the Copy AllRows Filled with 1 tab.

    And that is how i want it to be but i'd like the Dropdown to be in Sheet1 and when i moved it to Sheet1 the drop down selections give me blanks on the Copy AllRows Filled with 1 tab.

  13. #13
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Excel Code run when combox list item is selected.

    Hello cllaguno,

    Okay, that makes sense. I'll work on it and see what needs to changed in the code.

  14. #14
    Registered User
    Join Date
    07-10-2013
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Excel Code run when combox list item is selected.

    Question: You know how the code currently selects all rows and columns. What would i have to change so that it would select spcific columns. Like for instance only all rows but only columns Name, Data of Birth, City, Own a Home and not Columns E-G to show on Copy AllRows Filled with 1?

  15. #15
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Excel Code run when combox list item is selected.

    Hello cllaguno,

    The big problem is the Drop Down is on the ActiveSheet. It nevers sees the other sheet where the data is because it is no longer active.

    I have added a button to "Sheet1" that will display a UserForm. You can then select the sheet you want to copy the data from and select the marital status. Hopefully, this will work for you.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    07-10-2013
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Excel Code run when combox list item is selected.

    Is it possible to just have the drop down or is the form needed?

  17. #17
    Registered User
    Join Date
    07-10-2013
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Excel Code run when combox list item is selected.

    Is it possible to just have the drop down without the form?

  18. #18
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Excel Code run when combox list item is selected.

    Hello cllaguno,

    The only way to eliminate the form would be to include a command button on each sheet.

  19. #19
    Registered User
    Join Date
    07-10-2013
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Excel Code run when combox list item is selected.

    Thank you so much. All of this has made much more sense and now i've gotten the handle of it.

    I think this will be my final question, i hope............After i select on of the drop downs the cursor seems to go to random places. How can i adjust it the code so the cursor always ends on the tab and cell i'd like?

    thanks again.

+ 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