+ Reply to Thread
Results 1 to 8 of 8

ActiveX ComboBox selection writes multiple cells

  1. #1
    Registered User
    Join Date
    05-11-2007
    Posts
    6

    ActiveX ComboBox selection writes multiple cells

    I probably need to buy a book that is a good excel programming reference, but in the meantime, can someone provide me with example code (or better yet, example spreadsheet with code), that shows an ActiveX combobox with at least 2 selections, where say the first selection writes "bob" and "mary" to cells B5/C5, and the second selection writes "dog" and "cat".

    Once I see an example, I should be able to figure out the mechanics. I'm surprised that after a bunch of surfing, I wasn't able to find something like this anywhere.

    Thanks,

    David

  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,258
    Hello David,

    The best method is using a demo workbook. I have attached one here. There are 2 combo boxes (Control Toolbox a.k.a. ActiveX) and 2 command buttons. There is one command button for each combo box. The buttons load the combo boxes in different ways. List 1 is loaded using VBA code, and List 2 is loaded using a Range on the worksheet. The combo boxes each use 2 columns to store the data. I was sure if this is what you wanted or if you want store the entry as a single string separated by space e.g. "Bob Mary". The 2 columns seemed more likely.

    Sincerely,
    Leith Ross
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    05-11-2007
    Posts
    6
    Wow, thanks for the prompt reply. I spent hours digging elsewhere, and didn't get this far!

    This gives me a great starting point. What I'm trying to do is slightly different from this though; if you have a few moments, I'd really appreciate a demo of this.

    Say another worksheet in this workbook has the following 4 x 3 cell block:

    A 1 2 3
    B 4 5 6
    C 7 8 9

    - how do I populate the combo box drop-down selections with values from the 1st column range (A,B,C)? - ie. such that as soon as you open the workbook, these values are automatically already available as drop-down selections?

    - when one of the selections in the drop-down is chosen (A, B, or C), how do I fill the next three cells to the right of the combo box with values taken from the next three cells in the same row that the drop-down box came from? So if A is selected, the three cells to the right of the combo box would be filled with 1,2,3; if B selected, 4,5,6, etc.


    Given that all this is working, can the worksheet on which the 4 x 3 matrix is defined be hidden, so no one can see where these values are coming from?


    Thanks,

    David

  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,258
    Hello David,

    I made the changes to List 2. The data is on "Sheet3" which is hidden. Only the letters are shown in the ComboBox. When the user makes a selection the data is copied from the hidden sheet to the 3 cells to the right of the ComboBox. If you have any questions, just ask.

    Sincerely,
    Leith Ross
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    05-11-2007
    Posts
    6
    Leith,

    That's pretty much the functionality I was looking for. I adapted it to my spreadsheet, so now, the combo box on Sheet1 Cell B8 stuffs values into that row (it stuffs the grey text columns, which will be hidden, and then I calculate extended values based on column A quantity).

    What I need to do now is have the same functionality in about 20 rows below row 8 - where the exact same drop-down box selections allow a different item to be selected, quantities tabulated. For example, the combobox in B9 need to work exactly like the one in B8, but of course stuffs values into row 9.

    Instead of hard-coding the "Combobox" in the subroutine, I need to use variables and have the selection change apply to whichever row the new drop-down selection was made. I guess every combobox has to have a subroutine, right, but I'll need to have that subroutine call the main one, sending it a variable that makes the subroutine act on the row the selection was made in.

    The only other things I'll need, are:
    - to make the routine that stuffs values into the combobox run automatically when the spreadsheet is opened.
    - to make that routine also sense how many rows in Sheet 3 have data, and stuff the combobox with column A values for that number of rows (instead of hard-defining the Range A2:A5 as it is now).

    Thanks again for all your help.

    David
    Attached Files Attached Files
    Last edited by darmstrong; 05-13-2007 at 10:10 AM.

  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,258
    Hello David,

    I have added the functions you wanted to the attached workbook. The row is determined by the cell the ComboBox occupies, so you don't need to pass any variables. Just be careful of future placements. You will have to enter a single line of code for each ComboBox's Click() event. You will see the code on Sheet1. Everything else is automated.

    Sincerely,
    Leith Ross
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    05-11-2007
    Posts
    6

    Names function

    Leith,

    The structure you set me up with is working very well (Thanks again). My challenge now, is that I want to be able to make selections in the various combo boxes in the Product column (ModelRequirementBreakdown2a.xls), not only by using the combo box dropdown and select mechanism, but also, if possible, by pasting a cell range whose data matches that in the combobox definition.

    In other words, if I have a single column cell range from somewhere with the following data in 2 rows:
    VNXES
    HDX

    I want to be able to paste that range starting at B8, such that it makes the combobox selections in B8 and B9, and thereby populates rows 8 & 9 with the appropriate data.

    Is this do-able?



    I saw an example of another approach to data selection which I liked somewhat, but I don't think it will work. I thought I was good at figuring out things, but I can't crack this simple one.

    In the attached spreadsheet, cell A1 of Initial Quality worksheet has a drop down that apparently references the Namelist? "FieldeList" which is on the List worksheet, cells A1-A14.

    By examining A1 of Initial Quality, how can you determine that this reference exists?

    How do you establish such references to Namelists, with the drop-down arrows?

    I like this method of using drop-down lists better than ActiveX combo boxes, because once you've chosen what you want, the appearance is cleaner. Big problem however, is if you try to paste directly into the A1 cell, it doesn't select the item out of the namelist, it overwrites the cell, erasing the namelist functionality. Am I missing something?

    Thanks,

    David
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    05-11-2007
    Posts
    6
    Leith,

    Well, I finally did figure out how to use paste to make a combo box selection - the LinkedCell property of the combobox. I'm getting one odd behaviour though from the LoadComboBox macro you provided.

    Because I'm using paste into the LinkedCell under the combobox, it opens the possibility that a value not in the combobox listing may occur. When this occurs, for some reason, the LoadComboBox macro running time for that combobox (when opening the workbook) takes significantly longer to run (maybe 5-10 times). This is adding up, because I'm going to have maybe 50 repeats of the combobox, and there are 6000 items in the list (pushing a minute to open the workbook now)

    One other related behaviour, is that with Sheet1 filled out, when the workbook is opened, the already-selected data in the comboboxes is retained as expected when the combobox selections are loaded. For some reason though, if I trigger the LoadAllComboBoxes macro with a button after its open (for testing), the action of loading the comboboxes clears their current selection, except for lines that have data in the cells not found in the combobox list (the same cells taking longer to load the combobox). This isn't in and of itself an issue, but it may be a clue to the problem.

    If you have any ideas, it'd be great to hear them. This performance issue is one of the last big hurdles I have before putting this spreadsheet into use.

    Thanks again for your help.

    David

+ 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