+ Reply to Thread
Results 1 to 11 of 11

Macro to have user select Criteria

  1. #1
    Registered User
    Join Date
    10-31-2012
    Location
    orlando,florida
    MS-Off Ver
    Excel 2010
    Posts
    19

    Macro to have user select Criteria

    I would like a drop down list or a User Input box so the user can select what criteria for certain periods. I can get the Autofilter to work in my Macro but I cannot figure out how to get the values in the Dropdown or Input Box to have the user select the custom criteria. Any help would be appreciated.

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Macro to have user select Criteria

    you could use a userform.
    Depending on how many permutations you want, you could have say 4 text boxes in the form to enter the values then put them together as a string


    Please Login or Register  to view this content.
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

  3. #3
    Registered User
    Join Date
    10-31-2012
    Location
    orlando,florida
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Macro to have user select Criteria

    Getting the "Invalid use of Me Keyword. It is being called in the same module and I'm looking for solution and finding that it needs to be moved into its own module but usure how to accomplish this. Is this a ne Macro that has to be called from the original procedure?

  4. #4
    Registered User
    Join Date
    10-31-2012
    Location
    orlando,florida
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Macro to have user select Criteria

    I see that I may need to design a userform of some sort and anchor this code to the form. I'm reading up and would appreciate the assistance..

  5. #5
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Macro to have user select Criteria

    If you upload a workbook, i could add one for you.

  6. #6
    Registered User
    Join Date
    10-31-2012
    Location
    orlando,florida
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Macro to have user select Criteria

    I would like the user to be able to select the periods for the report based off of field 4 Column D. There can be a total of 5 periods for the months with 5 weeks. The attachment is a recreation of the report minus senitive data. The focus for the Usertestwkbk.xlsxform selection is based off of the Week Ending Periods.

  7. #7
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Macro to have user select Criteria

    I have updated the workbook with a userform. The list box will be populated with non duplicated periods to select.
    The Listbox is set for multi select so you can choose as many as you want. The selected items are then turned into an array and then the filter can be used. I think this is what you are after.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    10-31-2012
    Location
    orlando,florida
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Macro to have user select Criteria

    Sean,

    A little confused,

    This is great but I'm trying to follow the "Search" button in Worksheet1. I'm not sure what you did to get that there and how it calls UserForm1. My WorkSheet is a Different name so I know I need to change the code for that name.

    Also, how would I incorporate this into the Code that I'm using. Do I Call/Show this from my Sub Procedure and what do I Call/Show for the Search Button to appear in the ActiveSheet ? Is the UserForm1.Show I have Highlighted what needs to be The Call/Show, or is it one of the other Sub Procedures names? I don't see the Code for the Search Button unless it is
    Please Login or Register  to view this content.
    My Code
    Please Login or Register  to view this content.
    Thank you so much!
    Last edited by excelrcb3; 12-20-2012 at 12:55 PM.

  9. #9
    Registered User
    Join Date
    10-31-2012
    Location
    orlando,florida
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Macro to have user select Criteria

    I believe I found the answer to my question on how you placed the Search Button in the WorkSheet1, but I would like to still know how I could incorporate this into my code when the work sheet opens.

  10. #10
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Macro to have user select Criteria

    im a little confused what you are doing.

    are you opening a new file and using that data?
    basically to get the userform to show you must somewhere call the code Userform1.show

    This can be from either a commandbutton as i have used or you can add that line in another code if you want.
    ie. if you maybe are opening another document and copying data into your master doc first and then call the userform1.show to use.

    to add a search button to your own sheet, activate the sheet you want, select developer tab, insert,active control command button.
    then place this on your sheet, change the size, right click and edit the name if required.
    Then if you double click the button it will open the vba code sheet , and will add something like sub commandbutton1().
    if you then enter userform1.show then your code is ready when you click the button.

    Dont forget you will need to copy the userform from my document to your one.

    hope this helps.

  11. #11
    Registered User
    Join Date
    10-31-2012
    Location
    orlando,florida
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Macro to have user select Criteria

    Thanks for the help I got it to work. Great job!

+ 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