+ Reply to Thread
Results 1 to 9 of 9

VBA code for changing combobox value

Hybrid View

  1. #1
    Registered User
    Join Date
    09-13-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    49

    VBA code for changing combobox value

    Hi folks,

    It's been a while since I've posted something, because usually I can find what I'm looking for in exsisting threads. However, this time I guess I didn't phrase my search correctly, because I came up blank. So...here's my problem:

    We collect our research data in an excel spreadsheet. Some of our data have to be sent (in a special xml format) to a national database.
    The people from the database have provided us with an exporter spreadsheet which nicely translates our data to the correct xml format. However, we currently have to copy and paste our data to this spreadsheet manually. Which is of course not really a problem, but can go wrong if you have to do it several times in a row. So, I was planning to automise this through a macro.

    Seems simple enough, but as a part of the process, I have to select one of three options from a combobox included in the exporter spreadsheet. Since I've never written a macro with a combobox included in it before, my first idea was to simply record the macro. However, the part where I made my selection in de combobox was nowhere to be found in de resulting macro. It went straight from my last action before the combobox to my first action after the combobox.

    The question should be obvious by now: Can anybody tell my how to say in VBA : Select the combobox named cboX and set this combobox to option A, B or C ?

    Oh, since I don't know if this is important or not (I think not, but who am I?): The VBA in the exporter spreadsheet is password protected and I know for certain I'm not going to get that password.

    Thanks in advance
    Thirsa

  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: VBA code for changing combobox value

    Hello Thirsa,

    If the VBA Project is password protected, you will not be able to view or change the VBA code, unless you have the password.
    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
    09-13-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: VBA code for changing combobox value

    OK, I guess I wasn't completely clear.
    I know I won't be able to change the code in the exporter spreadsheet without the password. That is why I want to create a macro in my other spreadsheet (the one containing the data) which opens the exporter spreadsheet, selects the correct option in the combobox, then pastes my data into the exporter spreadsheet and saves the exporter spreadsheet under a specific name. I know how to do everything except the combobox part.
    So all the VBA code I will be making will be stored in my data-spreadsheet.
    The reason I asked about the password is because I don't know if the fact that the exporter spreadsheet is password protected will be a problem for programming the "select the correct option in the combobox" part of the macro.

    Hope this clarifies things. And thanks for replying.

  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: VBA code for changing combobox value

    Hello Thirsa,

    There are three different types of ComboBoxes that can be added to a worksheet: Data Validation, Forms, and ActiveX.

    Do you know which you have?

    What is the name of the worksheet it is on?

  5. #5
    Registered User
    Join Date
    09-13-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: VBA code for changing combobox value

    Unfortunately, I have no idea what type of combobox it is. Is there a way to tell which is which? This one looks like what you would get with the list option in the data validation menu, but it is not included in the cell. It's a separate control on top of the cell.

    The worksheet has simply been named 'data' by the makers.

  6. #6
    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: VBA code for changing combobox value

    Hello Thirsa,

    Can you post a copy of the workbook?

    How To Post Your Workbook
    1. At the bottom right of the Reply window, Click the button Go Advanced
    2. At the top of the Your Message Window, in the first row of icons, Click the Paperclip icon.
    3. Click the Add Files button at the top right in the dialog box. This displays the File Manager dialog.
    4. Click the Select Files button at the bottom middle of the dialog.
    5. In the new window Find the file you want to upload, select it, and Click Open.
    6. You will now be back in the File Manager dialog. Click the bottom Middle button Upload File.
    7. Wait until the file has completely uploaded before you exit the File Manager dialog.

  7. #7
    Registered User
    Join Date
    09-13-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: VBA code for changing combobox value

    Of course I can work around the problem by saving 3 blank versions of the exporter spreadsheet, one with each of the thee options selected in the combobox, and make a couple of ifs in the macro in order to open the correct one. But it would be nicer (and save disk space) if the macro could make the selection in the combobox.

  8. #8
    Registered User
    Join Date
    09-13-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: VBA code for changing combobox value

    Don't know if I'm allowed to post a copy of the spreadsheet, since I didn't make it myself and the people who did are very "squeemish" when it comes to privacy and copyright issues (it's not just the VBA which is password protected, it's the whole workbook and I wouldn't be surprised if they used 2 different passwords)...which I guess isn't surprising since they're part of the gouvernment and privacy really is a big issue in the work they and we do.

  9. #9
    Registered User
    Join Date
    09-13-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: VBA code for changing combobox value

    Back again.
    I wasn't at work the past couple of days and so couldn't check if I could figure out what type of combobox was present in the exporter spreadsheet. Turns out it's an ActiveX combobox. Don't know if that simplyfies things or makes them worse...
    I'm still looking for a way to include the making the selection in the combobox in the macro, but if nobody has any ideas I'll just have to use my workaround solution.

+ 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. Changing the value in Combobox after update
    By jik_ff in forum Access Programming / VBA / Macros
    Replies: 0
    Last Post: 04-17-2014, 09:34 PM
  2. changing lables based on a combobox based on another combobox
    By teacher_rob in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-09-2011, 04:00 AM
  3. Code to reset combobox dependant on another combobox
    By j.farr3ll in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-08-2011, 08:21 AM
  4. One Combobox changing another's rowsource
    By johnliquid in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-02-2011, 12:22 PM
  5. Changing combobox properties
    By leonidas in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-20-2006, 01:57 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