+ Reply to Thread
Results 1 to 9 of 9

Call 2 macros with listbox change

  1. #1
    Registered User
    Join Date
    09-03-2013
    Location
    Lafayette, Louisiana
    MS-Off Ver
    Excel 2007
    Posts
    15

    Call 2 macros with listbox change

    I want to execute two macros every time a listbox change event takes place...it will be the same two macros every time a different item is selected in the listbox. Based on what is selected in the multicolumn listbox, one macro copies data from the listbox range and passes it to multiple text box values. The other macro runs a Solver with this data. For some reason, the code only works when I select an item in the listbox for the first time. When I change the selected listbox item, nothing happens. Here is my code and thanks in advance for any help you can provide:

    Please Login or Register  to view this content.

    If I remove the Call Solver_Vs from the code, the Copy macro works fine when the listbox selection changes any number of times. If I create a command button to call the Solver_Vs, it will perform as desired every time I click the command button. So this makes me believe something is wrong in my For & if statement. Thoughts?

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,651

    Re: Call 2 macros with listbox change

    Can you show you Copy_ListBox1_Data code?
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    09-03-2013
    Location
    Lafayette, Louisiana
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Call 2 macros with listbox change

    As requested. Thanks for the prompt response.

    Please Login or Register  to view this content.
    Figured I would go ahead and paste the Solver macro as well:

    Please Login or Register  to view this content.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,651

    Re: Call 2 macros with listbox change

    The For-Next loop isn't necessary unless you have a multi-seletion listbox.
    Consider also to put the four lines that populate the textboxes within the ListBox1_Change procedure.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-03-2013
    Location
    Lafayette, Louisiana
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Call 2 macros with listbox change

    Thanks for the help, but I still have the same issue. If I remove the Call Solver_Vs, the listbox1 change procedure works fine. However with the call Solver_Vs added to the procedure, the textbox values as well as the Solver_Vs will only work for the first initial selection in the listbox. When I change the selection which changes values for the Solver_Vs, the textboxes do not update, and it appears that the solver runs again with the original parameters as opposed to the newly selected.

  6. #6
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Call 2 macros with listbox change

    I wonder if this is a solver problem or a listbox problem. Perhaps you could upload the file with listbox macro and solver model?

    Alf

  7. #7
    Registered User
    Join Date
    09-03-2013
    Location
    Lafayette, Louisiana
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Call 2 macros with listbox change

    Please see attached.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    09-03-2013
    Location
    Lafayette, Louisiana
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Call 2 macros with listbox change

    I'm still having the same issues, if you care to drop some knowledge.

  9. #9
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Call 2 macros with listbox change

    I've had a look at your solver macro and the thing I find strange is the constraint you set for B16 i.e. >= 0 and <= 1000 but as B16 is not a cell that solver can change these constraints are
    meaningless.

    So if you canged

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    then solver would be able to change B16 and testing I got a value of 0,406325304 for B16 but B15 changed from 0,406324303680428 to -0.0000010 so perhaps this is not the best of ideas.

    Sorry I could not be more helpfull.

    Alf

+ 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. [SOLVED] Call macro for the sheets selected in listbox
    By boon-yao.tek in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-31-2014, 01:04 AM
  2. Call ListBox through variable
    By BrianAll in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-25-2013, 07:09 PM
  3. Call a userform from a listbox selection
    By seanpears99 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-10-2013, 03:49 AM
  4. According to the criteria you want to call the data listbox
    By ersoyalanprovus in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-23-2009, 05:15 AM
  5. Call function to fill Listbox
    By ingineu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-03-2006, 08:13 PM

Tags for this Thread

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