+ Reply to Thread
Results 1 to 10 of 10

Can a Userform Combo Box selection run a macro based on the selections filtered criteria?

  1. #1
    Registered User
    Join Date
    08-22-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    9

    Can a Userform Combo Box selection run a macro based on the selections filtered criteria?

    Hello everyone, I have a question as to if the below scenario is possible.

    In my workbook, my data is stored on sheet “Main”, and I would like to know if it is possible to create the following code to run in a userform of excel:

    I would like all rows from sheet “Main”, that contain a value of “X” in column D to run an excel to word export macro individually. Each row contains data that will relate to a bookmark on a word export template file (docx). I already have a few template macros (that I've found on here!) that I will be able to tweak when the time comes... in order to manage my data export.

    As an example, if there were 15 rows of data that contained value “X” (from column D), the macro would have ran 15 times and 15 separate word documents would generate as a result.

    NOTE: The operation itself will be executed by a user form. “X” Value will be chosen by a Userform combo box, and a command button will start the macros once clicked. Also note “X”=ticket number i.e. “13-QA-000”.

    Is something like this possible?

    In summary: Userform combo box selection filters “Main” data for all data related to selection of “column D” i.e “X”. User presses a button that runs a macro for each row of data related to value “X”.
    This is my first time posting on here, so I would like to apologize if I didn’t follow any forum guidelines.

    Thanks all in advance!!!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Can a Userform Combo Box selection run a macro based on the selections filtered criter

    Yes it is possible.

    Here's some example code which you could run from a button on the userform.
    Please Login or Register  to view this content.
    [/code]
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    08-22-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Can a Userform Combo Box selection run a macro based on the selections filtered criter

    Thanks so much for the quick response!

    I briefly tried your code and it seems to work for my needs, I can't believe how easy you made that seem. I will need to finish my new export macro and new template to put it to the true test. I'm still not sure if the code will run the macro multiple times based on number of rows that equal my combo selection? I will post after I validate the operation...

    Thanks again,

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Can a Userform Combo Box selection run a macro based on the selections filtered criter

    The code will run the export macro every time it finds a match for the selected value in column D on 'Main'.

  5. #5
    Registered User
    Join Date
    08-22-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Can a Userform Combo Box selection run a macro based on the selections filtered criter

    You are correct. I only had test data in my workbook so I added two(2) lines of data with the same ticket number and it did call the macro 2x's! Very awesome.

    This may require a new thread, please advice if so...

    How will I get that separate data for each word popup to fill in the info for that line?

    As an example: I select 13-QA-001 (Lets say it has 3 alike rows) press the button--> it generates the first row of data into the word template putting in the correct data per that row of data.-->generates another putting in the data, but that data is different then the first one generated, only thing alike is the ticket number (qty. batch number. date fields are different).--> same thing for the third form...

    Would that be hard to acomplish? Would I need to detail the code in the excel to word macro vba?

    Thanks,

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Can a Userform Combo Box selection run a macro based on the selections filtered criter

    You could pass the data to your Word macro.

    Or you could just pass the row number (I) to that macro and then it could use that to retrieve the relevant qty, batch number etc.

  7. #7
    Registered User
    Join Date
    08-22-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Can a Userform Combo Box selection run a macro based on the selections filtered criter

    Ok. I will try this tomorrow. Thanks

  8. #8
    Registered User
    Join Date
    08-22-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Can a Userform Combo Box selection run a macro based on the selections filtered criter

    I've attached an example of the word macro. It will be much larger than this when I create it specifically for this form, but I was wondering if you could explain how I would "pass the row number (I) to that macro and then it could use that to retrieve the relevant qty, batch number etc."

    This is the macro (an example-actual will have more bookmarks, etc...) that runs after the user selects the ticket number and presses the button...

    Please Login or Register  to view this content.
    Thanks, I appreciate all the assistance thus far,

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Can a Userform Combo Box selection run a macro based on the selections filtered criter

    Change the heading to this,
    Please Login or Register  to view this content.
    and call it like this.
    Please Login or Register  to view this content.
    You would use lngRow in the code like this.
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    08-22-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    9

    Thumbs up Re: Can a Userform Combo Box selection run a macro based on the selections filtered criter

    This worked perfectly! I created my new form and the macro to go along with it. Next thing I will be doing is studying what we have done here so I can actually understand why you did what you did... which made this work.

    I can't thank you enough for your help, you saved me hours of searching other forum posts!

    this issue is solved. (not sure how to mark this thread as solved?)


    Hope you have a great weekend, Thanks,

+ 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. Display Charts in a UserForm based on Combo Box Selection
    By HangMan in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-26-2016, 09:00 AM
  2. [SOLVED] Combo Box2 selections available based on Combo box 1 selection
    By wishn4fishn in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-28-2013, 08:13 PM
  3. Replies: 0
    Last Post: 06-25-2013, 09:42 AM
  4. Populate a textbox in a userform using multiple selections from a combo box
    By kksf in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-23-2013, 10:59 AM
  5. Recognize Userform Combo-box Selections as Range.
    By jasperhuang93 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-30-2012, 10:50 AM

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