+ Reply to Thread
Results 1 to 4 of 4

Adapt VBA script to add criteria to randomize filter

  1. #1
    Registered User
    Join Date
    07-01-2015
    Location
    Antwerp
    MS-Off Ver
    2019
    Posts
    71

    Adapt VBA script to add criteria to randomize filter

    Hi,

    Attached, you can find a workbook that contains a button on the first tab. The button generates monthly sheet tables containing names of people (short names or "shorts") that are randomly filtered from a main table.

    Do you know how to adapt the VBA code in order to include the criteria below in the combined rows 4, 5 and 6 of each generated month sheet?

    • Row 4: Shorts with two criteria "Full revision" and "Overwork" that are filtered from the table on the main table sheet. Per day, this short in row 4 has to be different from the shorts in rows 5 and 6. A short of row 4 can only be used once a week and maximum twice a month. Preferably, the line of VBA code defining the monthly maximum is customisable (i.e. easily editable to e.g. once a month).

    • Rows 5 and 6: Shorts with two criteria "Translation" and "Overwork".

    • Combined rows 4, 5 and 6: Per day, the shorts in rows 4, 5 and 6 have to be unique. For the combined rows 4, 5 and 6, there also cannot be similar shorts on an adjacent day in the same working week.
      Example: a short of row 5 on Monday cannot be the same short of row 4 on Tuesday, but it could be the same short as row 6 on Friday of the previous week.

    • Shorts of rows 4, 5 and 6 can be used maximum 4 times a month if the short works 76-100%, 3 times a month if 51-75%, and 2 times a month if 0-50% (for the exact percentages, see "full/part time" column of the table in the main table sheet). If a month has not been completely filled out in the rows 4, 5 or 6, all shorts must be maximized. Example: a 100% short cannot be only filled in 3 times a month, it should be filled in 4 times a month. This also means that no short can work less than twice a month, nor more than four times a month.
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    01-25-2013
    Location
    near Philly, PA USA
    MS-Off Ver
    Excel 2019
    Posts
    178

    Re: Adapt VBA script to add criteria to randomize filter

    Might it make sense for the worksheets to do some of the prework for the macro?
    I didn't quite follow all of the criteria needed to implement but it would seem that the "shorts" lists could be developed by something like if statements then have the macro operate on these shortened preselected lists.

  3. #3
    Registered User
    Join Date
    07-01-2015
    Location
    Antwerp
    MS-Off Ver
    2019
    Posts
    71

    Re: Adapt VBA script to add criteria to randomize filter

    That is indeed the reason I turn to you. The prework has been done until the point that I am lacking the proper VBA knowledge to incorporate the criteria mentioned. I have no idea on how to implement working if statements on the randomizer.

    The criteria that have been correctly included so far (prework):
    - row 4 shorts are filtered from table columns "Full revision" and "Overwork"
    - row 4 shorts are only used once a week
    - rows 5 and 6 are filtered from table columns "Translation" and "Overwork"

    The criteria still to include:
    - row 4 shorts can only be used maximum twice a month (with the current vba code this is not the case: see shorts highlighted in orange on the attached image of an automatically generated month sheet)
    - per day, the shorts in rows 4, 5 and 6 have to be unique (with the current code this is not the case: see shorts highlighted in red on the attached image)
    - in rows 4, 5 and 6, the same shorts cannot appear more than once on an adjacent day in the same working week (with the current code this is not the case: see shorts highlighted in blue on the attached image)
    - the shorts of the combined rows 4, 5 and 6 can be used maximum 4 times a month if the short works 76-100%, 3 times a month if 51-75%, and 2 times a month if 0-50% (for the exact percentages, see "full/part time" column of the table in the main table sheet). If a month has not been completely filled out (i.e. some cells stay empty) in the rows 4, 5 or 6, all shorts must be maximized. Example: a 100% short cannot be only filled in 3 times a month, it should be filled in 4 times a month.
    - in the combined rows 4, 5 and 6, no short can work less than twice a month, nor more than four times a month
    Attached Images Attached Images
    Last edited by Retroshift; 04-30-2023 at 04:04 AM.

  4. #4
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Adapt VBA script to add criteria to randomize filter

    another attempt, I used the holidays in France in the sheets "Jours_Fériés" because that was the easiest way to create (and easy to adapt)
    Then, in sheet "Blad13", i assign your persons every month of 2023
    In columns G:H, you find the number of occurences in row4 and in row4-6.
    Attached Files Attached Files
    Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

+ 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. excel filter function: trying to adapt and getting error
    By masterx7 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-23-2020, 09:46 PM
  2. [SOLVED] Need to Adapt VBA Script for my file
    By MermaidNiki in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-20-2017, 07:23 PM
  3. Code to randomize within a filter
    By ScottBeatty in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-30-2013, 04:32 PM
  4. Excel 2007 : Need to sort & randomize by certain criteria
    By Snowberri24 in forum Excel General
    Replies: 0
    Last Post: 12-15-2010, 06:37 PM
  5. Advanced Filter VB Script for Variable Criteria Range
    By Jason in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-19-2006, 02:15 AM
  6. [SOLVED] Adapt code to show filter
    By Jack in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-19-2006, 07:25 AM
  7. Replies: 1
    Last Post: 02-24-2005, 06:26 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