+ Reply to Thread
Results 1 to 7 of 7

VBA Automatic Timetable Population

  1. #1
    Registered User
    Join Date
    12-08-2014
    Location
    Brisbane, Australia
    MS-Off Ver
    2010
    Posts
    7

    VBA Automatic Timetable Population

    I have a worksheet with children's names and their 3 preferences (day & time) for swimming classes. I have a second worksheet that contains a timetable with days Monday-Saturday across the top and down the side 6 available slots for each time available for each class time.
    I need a VBA that will take the child's first day/time preference and if available place their name in the timetable with their corresponding grade and then highlight the child's assigned preference in blue in the first worksheet. If the first day/time preference is taken, then see if the 2nd preference is available and if this is taken, then check the 3rd preference. If all preferences are taken then highlight the child's name in red so that I know that they have not been assigned a spot in the timetable.
    If all of the 6 available slots for a specific day/time are filled when it checks the child's first preference then I want it to go to the next preference and so on.

    Worksheet 1
    Column A = Name
    Column B = Grade
    Column C = Preference 1 Day
    Column D = Preference 1 Time
    Column E = Preference 2 Day
    Column F = Preference 2 Time
    Column G = Preference 3 Day
    Column H = Preference 3 Time

    Worksheet 2
    Column A = Class Time
    Column B = Monday (cells for child's name)
    Column C = Grade (child's grade)
    Column D = Tuesday (cells for child's name)
    Column E = Grade (child's grade)
    Column F = Wednesday (cells for child's name)
    Column G = Grade (child's grade)
    Column H = Thursday (cells for child's name)
    Column I = Grade (child's grade)
    Column J = Friday (cells for child's name)
    Column K = Grade (child's grade)
    Column L = Saturday (cells for child's name)
    Column M = Grade (child's grade)

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: VBA Automatic Timetable Population

    It can be done the way you described, but I think it is not fair if you look at the children, who are near the end of your list.
    I assume (may be I'm wrong) that all children shall have equal chances to be assigned their classes, and also all shall have equal chances they are assigned their first choice.

    i'd probably introduce a kind of weights like - first choice assigned = 0, second choice 1, third choice = 3 (may be 2 or 4) byt no assignment - weight at least 10. And then look for assignments with lowest sum of weights for all children.

    To do it proper way an estimate of the number of timeslots (we know each timeslot have 6 "nameslots") per day and an estimate of total number of children would be nice.

    Good idea would be also to post some dummy data (see how to add attachment here: http://www.excelforum.com/forum-rule...rum-rules.html ) to play with.
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    12-08-2014
    Location
    Brisbane, Australia
    MS-Off Ver
    2010
    Posts
    7

    Re: VBA Automatic Timetable Population

    Thanks for your reply Kaper.

    The children are placed in the spreadsheet as they are received from the parents and places are given on afirst in best dressed situation, so the first child on the list is the first one received back from the parents and so they get the first pick of day/time.

    I have attached a sample workbook that contains dummy data.
    Attached Files Attached Files

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: VBA Automatic Timetable Population

    Sample code could be:
    Please Login or Register  to view this content.
    As your test data was prepared that way that all children could take 1st pref, a added some and randomized file a bit - see attachment.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    12-08-2014
    Location
    Brisbane, Australia
    MS-Off Ver
    2010
    Posts
    7

    Re: VBA Automatic Timetable Population

    Kaper that is fantastic thanks very much!

    I was wondering if you would be able to make a change? I have made a specific class time either a grade 1 or a grade 2 level class only, so when it goes through the list of children and their preferences they will only be assigned to a preference if it is in their level, therefore if a child is a Grade 2 but their first preference day/time is allocated a Grade 1 class only, then it goes to the next preference, then the next if the same occurs, then if none available their name is highlighted in red.

    I have attached an updated spreadsheet with the changes to the timetable layout.

    Once again, thanks very much for your help
    Attached Files Attached Files

  6. #6
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: VBA Automatic Timetable Population

    It can be done with minor change (2 places) in try function.
    The inner loop would look now:
    Please Login or Register  to view this content.
    Or, as I expect the classes will be one grade only (no classes with 3 Grade 1 and 3 Grade 2 combined) checking moved outside a loop (will optimize performance somewhat):
    Please Login or Register  to view this content.
    PS. Side effect of this is that if for instance you would like to have Wednesdays morning part only till 11AM (last class starts at 10:30) you just leave cells G32:G34 on timetable sheet empty and no children will be assigned there.

  7. #7
    Registered User
    Join Date
    12-08-2014
    Location
    Brisbane, Australia
    MS-Off Ver
    2010
    Posts
    7

    Re: VBA Automatic Timetable Population

    Thanks so very much Kaper it works perfectly!

+ 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. VBA for automatic Hyperlink population
    By jakeisbill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-03-2013, 01:49 PM
  2. Automatic Population
    By mediumquality in forum Excel General
    Replies: 6
    Last Post: 03-28-2012, 06:39 AM
  3. [SOLVED] Automatic Population?
    By Stacey in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-08-2006, 06:50 PM
  4. Automatic Cell Population
    By EJ in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-24-2006, 08:52 AM
  5. [SOLVED] Automatic cell population
    By MazzyMirsa in forum Excel General
    Replies: 3
    Last Post: 02-09-2006, 02:20 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