This was posted originally at StackOverflow though suggested to post here instead.I am looking to create an Excel VBA solution that will create a rota/schedule allocating staff to service users using an algorithm. I believe there are already existing names for this kind of problem/algorithms but not entirely sure what to refer to it is.Here is my scenario:A colleague approached me with a problem of scheduling staff against visits required. Currently this is a manual process done every week and is labour intensive. The datasets are small, on average there would be 20 service users each requiring 2 visits a day with 5 members of staff available each day.I have a worksheet that contains the list of staff who are available for the following week. Each row of data contains their name, gender, skill level, home postcode, day working, start time and end time. A member of staff may be listed more than once on the same day as they may be available for hours in the morning and also in the evening.Another worksheet contains the list of service users and visits required for the following week. Each row of data contains their name, postcode, day of visit, time of visit, visit duration, gender required (i.e. must be seen by a male/female), skill level required (i.e. any, certified) and the number of staff required for that visit (i.e. 1 or 2). Again a service user may appear more than once on the same day as they may require multiple visits at different times of the day (i.e. morning and evening)I have already created some VBA functions to deal with handling of postcodes and getting latitude/longitude co-ordinates along with a function to calculate the distance between two points as the crow flies. At present the distinct values of postcodes with there co-ordinates are being stored on a helper sheet for the VBA to reference.What I am really looking for is guidance on how to even being creating a procedure/algorithm which will produce a suggested rota/schedule, this could be a simple table with pairings between staff and visits. The process must always make suitable pairings based on:Skill Level RequiredGender RequiredStaff AvailabilityLeast important are that matches take into consideration the distance required to travel between visits. I believe this is referred to as a Genetic Algorithm?There may be instances where there are too many service users for the available staff and vice versa. Making use of all staff isn't necessary provided all visits are dealt with, if all visits cannot be paired due to a lack of staff availability then this needs to be listed as being unmet.I can utilize SQL Server if need be but ultimately the solution needs to be presented in Excel to the end user, as this is what they are most familiar with.I'm thinking the procedure/process would need to go something like this:For each day, sort the visits by start timeFor each visit, determine which staff members meet the gender andskill level requirement and is available on that dayFor each of the staff member determined above, are they available atthe time requested?For each staff member that is available calculate the distance fromtheir current location to the where they need to beRank them in order of preference by distance required to travelOnce this has been done for each day, come up with a suggestedallocation of staff to visits using some kind of scoring methodI'm no VBA expert and deal with SQL Server as my day job but I am willing to try and come up with a suitable solution, just need some guidance on how best to start.
Guidance on Excel VBA resource scheduling algorithm?
algorithms;scheduling;excel;rules and constraints;vba
I have some experience with the sort of scheduling problem you present, and the technical stack you're using, and so I can speak from authority and say this is a database problem and belongs in SQL Server, not Excel!.Assuming that these are regular visits that are already scheduled and you only need to allocate your staff to the various tasks, (and staff have to return to their home office between visits), I recommend the following process:Migrate your staff list to a normalized table structure, with separate Employee and Availability tables.Do the same to your service users, with Customer and Visit tables.  (How you populate the visits is a different question.)Create a distinct Assignment table, that reflects the assignments you give your staff.  This table will include both actual shifts, and necessary non-visit assignments (such as drive across town).  Your program will generate suggestions, but you need to allow a human to revise the list.Generate a complexity score for each visit, by adding all the necessary requirements together.  (Must be seen by two certified women for 3 hours may be seven points, for example.)For the highest complexity value, make all assignments for your time period for all visits on that assignment.  Do this one row at a time, with tie-breakers based on the visit length and start-time.  Select staff who meet the needs based on availability and then some sensible sort value (seniority or times done this shift.)Mark a travel time entry for the assigned staff between the customer's location and the employee's central location.Repeat from #5, above, until all visits are satisfied.Return to Excel two lists, one of Customer Visits that indicates the assigned employees(s), and one of Employee assignments that notes the times each employee will be assigned.  Include any highlight in both any unassigned items.There are professional Workforce Management systems that will much of this for you, but such require several tens of thousands of dollars to purchase and assume you'll have an employee doing much of the work manually.  If they were doing this in Excel by hand, any automation will be an aid, and you can improve as you go on.(And take a look at .NET or Access to replace Excel in some instances; round-tripping data from Excel back to SQL Server is significantly harder than just making a form for a SQL server table in Access.)