+ Reply to Thread
Results 1 to 5 of 5

Pass value from combo box to a variable

  1. #1
    Registered User
    Join Date
    02-21-2007
    Posts
    20

    Pass value from combo box to a variable

    Hello,

    Scenario:

    On opening of the excel macro file, a user form loads.
    1. User selects a period from the drop down box which is populated from a range in the excel sheet called "Month".
    2. User clicks on the next button "Import Finance" to import data from 1 source file. Separate Module created to import the Finance data.
    3. User clicks on the next button "Import Lines" to import data from 2nd source file.
    Separate Module created to import the Lines data.
    4. User clicks on the next button to compare the data from imported from step 2 and step 3. Separate Module to compare the data.

    While all the this is going on, the form is visible and never unloads or hides. My question is how can I grab the month from the combo box into a variable to pass to the variable in the module in Step 4?

    Thanks,

  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

    Re: Pass value from combo box to a variable

    Hello zwieback89,

    This Code example assumes the name of the ComboBox to be "ComboBox1" on the UserForm. Pass the string variable "sMonth" as an argument to a procedure in your module.
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 08-26-2011 at 10:24 PM.
    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
    02-21-2007
    Posts
    20

    Re: Pass value from combo box to a variable

    Thanks for response. The comboBox is on the UserForm. On which event associated to the ComboBox, do I grab the Month chosen by the user?

    I currently have it on the Change event.

    Please Login or Register  to view this content.
    Public Function to return the month to the procedure that needs it. However, it seems I enter into an infite loop and the chosen month appears as a Message the whole time. What makes this go into the infinite loop?

    Please Login or Register  to view this content.
    Procedure that needs the above month:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Pass value from combo box to a variable

    You won't need a variable if you add a button in the userform to do the comparison:

    Please Login or Register  to view this content.



  5. #5
    Registered User
    Join Date
    02-21-2007
    Posts
    20

    Re: Pass value from combo box to a variable

    Thanks for the tip. I was able to get the value by referencing to the Form combo box and use it according. That eliminated the need to use of a function.

    Thanks to all for you suggestions.

+ 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