+ Reply to Thread
Results 1 to 10 of 10

Create List based on criteria (VBA)

  1. #1
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Create List based on criteria (VBA)

    Dear all,

    I hope you are all well.

    I am struggling to create a VBA code under Worksheet SelectionChange event.

    I have attached a test file.

    In Sheet1 I have a table with some information.

    Now in Sheet2 I need to create dynamic table based on selection (Yellow cells).

    For example, in Sheet2, if a user selects a region (e.g. EMEA) I want to populate all employees ID; Name; *** and Manager name.

    Tried to use functions but could not do it.

    Any assistance will be highly appreciated.

    Best regards,
    Filipe
    Attached Files Attached Files

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: Create List based on criteria (VBA)

    Hi Filipe,

    You said you are struggling to create a VBA code, so I will assume that you have some experience and are interested in expanding your knowledge of VBA code. What I have done is write some code to help you achieve part of your objective as I see it. I want you to try and finish it. I am here to help you.

    What I did was on sheet2 I made a list of the employee ID's in column Q to serve as the data for a drop down list which is where you will pick the ID numbers in A3.

    The selection change event is triggered when you click on a cell other than the one that is currently selected so I instead chose to use the change event. The code is triggered every time you make a different selection in the drop down list.

    The code in the change event checks to see what cell triggered the change event and if it was cell A3 it calls a macro, so look in module one and you will see the macro that is triggered. The macro clears any previous data from sheet2, auto filters sheet1 according to the employee ID selected, hides the columns you don't want on sheet2, copies the data over to sheet2, unhides the columns that were hidden and removes the filter.

    The code is below and the workbook is below the code.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  3. #3
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Create List based on criteria (VBA)

    Hi skywriter,

    First, let me thank you for your time and focus on this.

    I had a formula that worked well for this purpose. I am more confused on the other two tables.

    The employee ID will only show one row of data which is the employee that you choose. The other two (Manager & Region) are dynamic tables. For these ones I am struggling to create the VBA code to show/create a table based on the criteria. If the criteria changes, the table will change it's contents as well.

    Yes, I know a bit of VBA experience but to be honest, I know pieces and bits that I join together. Unfortunately I do not have much spare time to learn it as it should.

    Any ideas will be highly appreciated.

    Best regards,
    Filipe

  4. #4
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: Create List based on criteria (VBA)

    Good Luck.


    If your original request is fulfilled please click the Thread Tools drop down box above your first post and choose solved.

    If you are happy with my help, please consider clicking the add reputation button in the lower left hand corner of this post.
    Attached Files Attached Files

  5. #5
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Create List based on criteria (VBA)

    Hi skywriter,

    Thanks a million for your support.

    This is just what I was looking for.

    Now I have to struggle (not that much now, thanks to you ) on fitting on my own file that has +50 columns and +500 rows...

    Once again, your assistance on this is highly appreciated. Thanks for all your help.

    Cheers,
    Filipe

  6. #6
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: Create List based on criteria (VBA)

    I can explain the code where needed to help you adapt it to your actual file.
    Thanks for the rep. points.

  7. #7
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Create List based on criteria (VBA)

    Hey Skywriter,

    I will accept your offer indeed and thanks a million for that.

    The only thing that I don't understand on your code is how it fills the information on the right columns?

    I mean, there are no references about the columns where to update the required information or else, the code itself is recognizing the same column names??

    As I mention, my real workbook table have +50 columns and +500 rows and I might want to retrieve the information e.g. from column 5; 25; 3; 16... if you know what I mean.

    Thanks a million in advance.

    Cheers,
    Filipe

  8. #8
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: Create List based on criteria (VBA)

    On sheet2 in cell F3 you wanted to filter by manager name. Changing the manager name triggers the worksheet change event. The value of the manger name is passed to the Sub named FilteredManagerData(Manager). This (Manager) is the name of the manager getting passed from the worksheet change event to the sub procedure.

    The section of code below filters your data on sheet1 according to the manager name, it then hides the Gender column and the Manager column because you didn't want that data on the second sheet, it then copies the visible data and simply pastes it to cell F5 on the second sheet. Then it unhides the hidden columns and removes the filter. This of course all takes place in a fraction of a second and you never notice it because you are on the second sheet when this happens and screen updating is turned off.

    Please Login or Register  to view this content.
    Last edited by skywriter; 04-30-2015 at 03:38 PM.

  9. #9
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Create List based on criteria (VBA)

    Thanks Skywriter,

    Yes now I see how it works

    And yes, I was wondering why it was filtering... I should have used a bit more my burned brain hehehe.

    Now the question will be, with my real table, will I have problems with performance? With all the filtering and copying the info?

    Well, I will only know as soon I'll try it.

    Anyway Skywriter, your help was outstanding on this matter. Will not bother you again on this subject. Unfortunately I cannot add more reputation...

    Thanks for all your time and help on this.

    Cheers,
    Filipe

  10. #10
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: Create List based on criteria (VBA)

    You are not bothering me. Everyone here, is here to help, if I don't reply to a post I'm sure someone will.
    Good Luck!!!

+ 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] Create list of combinations based on changing criteria
    By NamiSama in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-15-2014, 01:41 PM
  2. [SOLVED] Create a distinct list based on other criteria
    By tomtheappraiser in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-29-2014, 12:59 PM
  3. [SOLVED] Create list based on criteria and is unique
    By joannelittell in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 10-13-2013, 02:33 PM
  4. [SOLVED] Create a list that has more than one column based on a criteria
    By limebaish in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-01-2013, 09:21 PM
  5. [SOLVED] Create a separate list based on criteria in another list.
    By dpitts21 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-13-2012, 07:09 PM

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