+ Reply to Thread
Results 1 to 20 of 20

VBA code to click/select drop down lists

  1. #1
    Registered User
    Join Date
    11-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    80

    VBA code to click/select drop down lists

    I have a userform that I have created, and as the user goes through the drop downs, it filters the next drop down list in order. What i would like to do, is have some VBA code that simulates a user clicking on a drop down box and making a selection. Is there a way to do this? I want to automate some steps basically and I need to simulate this.

    Thanks!

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA code to click/select drop down lists

    What do you mean by simulate? Like make a selection in the combobox?

    You can use code to change the value of a combobox but i don't believe it will trigger a click event, what event are you trying to 'simulate'?
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Registered User
    Join Date
    11-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    80

    Re: VBA code to click/select drop down lists

    I'm trying to simulate the clicking of the combobox, and selecting a certain value. When the user does this and makes a selection, it filters the combobox next to it. so I am trying to make an automated version of a user going through and clicking comboboxes and their values.

  4. #4
    Registered User
    Join Date
    11-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    80

    Re: VBA code to click/select drop down lists

    So basically, Combobox_Change() will initiate the script to filter the next combobox

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Why do you need the combobox?

    Can't you just loop through the data it's populated with?
    If posting code please use code tags, see here.

  6. #6
    Registered User
    Join Date
    11-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    80

    Re: VBA code to click/select drop down lists

    Well I was basically trying to skip re-writing all the code that goes into filtering the comboboxes. I think I have figured it out... if I make the selection what I want, and then call that combobox_change() sub, it seems to be doing what I want. I guess just needed to type out my question lol.

  7. #7
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA code to click/select drop down lists

    So you're writing code to test your code?

    Seems kinda circular.

  8. #8
    Registered User
    Join Date
    11-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    80

    Re: VBA code to click/select drop down lists

    Quote Originally Posted by XeRo Solus View Post
    So you're writing code to test your code?

    Seems kinda circular.
    It is. What my program does right now, is gives the user the ability to go through drop down lists to formulate a part number, and then it runs a macro which spits out the build of material. The drop down lists are all running their own macros, in order to only provide correct part numbers.

    What I am now programming, is the ability to just enter in an already created part number, press a button, and get the build of material. I am decoding each part number, piece by piece, and then basically running it through my initial program, as if they entered it themselves. The reason for this, is that all of the checks and balances are already built in to make sure a correct part number is created. If I do it this way, I can make sure that each piece they put in, matches up with whats in the combobox.

    Here is my issue now though. I can set the combobox to a value with "combobox1 = value" except this doesn't select a value that has been pre-filtered in the list. Is there a way that instead of just setting the combobox to a value, I can select a value? That way if the value isn't there, I can throw up a msgbox, stating it is an invalid part number..

  9. #9
    Registered User
    Join Date
    11-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    80

    Re: VBA code to click/select drop down lists

    I'll run this by you...

    The other way I can do it, would be to loop my program, to make every single valid part number there is instead of "decoding" them each time one by one. The issue with this, is there would be millions of part numbers, way more than excel can handle so I would have to probably export them to a DB file and read/write from there.

    Would this be easier?

  10. #10
    Registered User
    Join Date
    11-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    80

    Re: VBA code to click/select drop down lists

    Edit: Double post

  11. #11
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA code to click/select drop down lists

    I'm assuming there are fairly strict rules for what constitutes a valid part number and what doesn't.

    Can you check for those at the beginning of the button click?

    If they're not valid then msgbox please enter valid part number.

  12. #12
    Registered User
    Join Date
    11-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    80

    Re: VBA code to click/select drop down lists

    Quote Originally Posted by XeRo Solus View Post
    I'm assuming there are fairly strict rules for what constitutes a valid part number and what doesn't.

    Can you check for those at the beginning of the button click?

    If they're not valid then msgbox please enter valid part number.
    Well I have to check each individual piece of the part number. Its more like, the part number is broken down into 8 sections or so. Each section can have its own set of values, which is determined by the former. This is why I've built this program, to make it easier for people to put them together.

    I think I've figured everything out, except the selecting of a value only of its in the drop down. Any ideas how I can do that? For instance, if the part number I'm checking has an "X" in position 10, and the drop down usually responsible for the selection of this by the user only shows "Y", "W", "Z" as options, I need it to throw the message box up that says "Invalid part number" and require them to change it before the program proceeds.

    Edit: It needs to go like this:

    If the value I am checking for, is in the range of selectable values in the combobox, assign combobox to that value. Otherwise, throw up the MSG box.
    Last edited by hockeyadc; 07-26-2013 at 10:59 AM.

  13. #13
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA code to click/select drop down lists

    You'll have to loop through the list of the combobox checking all items in the lest against the "section" of part number that it corresponds to.

  14. #14
    Registered User
    Join Date
    11-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    80

    Re: VBA code to click/select drop down lists

    Quote Originally Posted by XeRo Solus View Post
    You'll have to loop through the list of the combobox checking all items in the lest against the "section" of part number that it corresponds to.
    Is there a way I can do some kind of "contains" code? For instance, if Combobox.list contains value then....

    How would I look through them? As a combobox index item?

  15. #15
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA code to click/select drop down lists

    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    11-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    80

    Re: VBA code to click/select drop down lists

    Quote Originally Posted by XeRo Solus View Post
    Please Login or Register  to view this content.

    Nice! Thank you. Starting to think I should have just made this in Access or another language to begin with...

  17. #17
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA code to click/select drop down lists

    Well VBA works in access as well. I'm not sure I understand the entire scope of what you're trying to accomplish so I can't comment on that.

    If you're looking at storing data access is a good bet. If you'd like to modify, compile etc, then I'd stick with excel.

  18. #18
    Registered User
    Join Date
    11-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    80

    Re: VBA code to click/select drop down lists

    Wait a sec, VBA works in access too? I thought it was only MYSQL!

  19. #19
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA code to click/select drop down lists

    VBA works for most Microsoft applications. Word,outlook,IE,Powerpoint. Its Visual Basic changed to apply to Applications = VBA (as apposed to VB.Net)

  20. #20
    Registered User
    Join Date
    11-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    80

    Re: VBA code to click/select drop down lists

    Thanks for the tip!

+ 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. Improved: select all code with one click
    By mahju in forum The Water Cooler
    Replies: 0
    Last Post: 04-15-2012, 09:39 AM
  2. VBA code for Locking Cell disabling Drop Downs Validation Lists
    By Leox5000 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-28-2012, 08:43 AM
  3. How to use any formula with multi-select or drop down lists?
    By heatham in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-06-2010, 05:07 PM
  4. Multiple drop-down lists to select different values from a table
    By joeyeti in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-09-2007, 05:40 PM
  5. Replies: 2
    Last Post: 04-23-2005, 12:06 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