+ Reply to Thread
Results 1 to 12 of 12

Using VBA to cross-reference class & teacher schedules

  1. #1
    Registered User
    Join Date
    03-15-2015
    Location
    Canada
    MS-Off Ver
    Mac 2011
    Posts
    8

    Using VBA to cross-reference class & teacher schedules

    Hi all -

    I'm new to VBA but familiar with programming concepts in general. I'm willing to do the work, but just hoping someone can let me know if what I need to do is possible and point me in the right direction for where I should focus my efforts.

    I'd like to create a workbook that lets me work out elementary teacher/class timetables and in the end, allows me to print off teachers' and class' schedules. For example, I want to print off the "grade one" class schedule so they know when they have gym, music, drama, etc, and then also print off the gym teacher's schedule so that he/she knows which classes will be visiting the gym and when. This needs to be replicated for every class (about 35 of them) and every specialty teacher (about 10 of them).

    Each day has 8 periods and each cycle has 10 days (meaning, each class & teacher has 80 possible "blocks" to schedule) - I have created a master "template" worksheet with periods down the first column and days 1 through 10 across the header row. In the past, this template would be duplicated and then scheduling would be done by hand - but it is very labour intensive and very prone to human error.

    Schedules need to be cross-referenced with each other such that, for example, if the gym teacher teaches the grade one class during period 2 on days 1, 3, 5 and 7, that information will show up on both the class' schedule and the gym teachers' schedule at the same times.

    Ideally, I'd love for excel to be able to alert me if I accidentally try to double book a class or a teacher.

    So far, I have created a worksheet for each class and each teacher, copied from my "template" worksheet. I also have another worksheet that lists the names of each of the specialty teachers. I then created drop down boxes for each "block" on the schedule so that you can simply click and select the teacher the class will have during each period. I have figured out how to have these drop down boxes trigger a macro, such that when you select a teacher from the drop down, "something" will happen.

    What I don't know how to code is that "something".... what I want is if I pick "gym" on Day 1, Period 1, it will first check if the gym teacher is available that period, and if so, will copy the name of that class onto the gym teacher's schedule. Preferably, the opposite could also work - if I pick "grade two" on the gym teacher's schedule during period 4, day 5, that it would check the class to see if it was free that period, and if so, input "gym" into their schedule.

    I hope that makes sense.

    Am I on the right track?

    What I need it to do is:

    (User selects a cell (representing a block of time on the schedule), selects a specialty subject or grade from the drop down menu.)
    - Copy name of worksheet (=name of the class or subject) [If copying name of the worksheet is not possible, I also have the needed text in a cell elsewhere in the worksheet]
    - If identical cell location in destination worksheet (specialty teacher's schedule or class schedule) is empty, paste
    - If identical cell location in destination worksheet is full, return error message
    Last edited by eureka987; 03-15-2015 at 08:31 PM. Reason: Further details

  2. #2
    Registered User
    Join Date
    03-15-2015
    Location
    Canada
    MS-Off Ver
    Mac 2011
    Posts
    8

    Re: Using VBA to cross-reference class & teacher schedules

    All I really need is to know if what I want to do is possible or not... anyone?

  3. #3
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Using VBA to cross-reference class & teacher schedules

    Sure, it's doable.

    I think you'd get a better response if you showed a before workbook, and an after workbook that demonstrated all of the features you want.

  4. #4
    Registered User
    Join Date
    03-15-2015
    Location
    Canada
    MS-Off Ver
    Mac 2011
    Posts
    8

    Re: Using VBA to cross-reference class & teacher schedules

    Timetable Example.xls

    Here is what I have so far. I'm starting with a small sample to try to test before expanding to all the classes & teachers I ultimately need. I'm not sure what you mean by "before" and "after". Currently, I can select classes or teachers but it's missing the automated piece that will avoid the need to do the cross referencing manually.

  5. #5
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Using VBA to cross-reference class & teacher schedules

    "Before" means what the sheets look like before any code is run
    "After" means how you would like the sheets to look after the code is run

  6. #6
    Registered User
    Join Date
    03-15-2015
    Location
    Canada
    MS-Off Ver
    Mac 2011
    Posts
    8

    Re: Using VBA to cross-reference class & teacher schedules

    And here is it again with a bit more data thrown in to work with.

    Currently if I assign class 1A to have "Smith" (gym teacher), I then have to go to Smith's schedule and manually input 1A at the same block of time. I want to eliminate this duplication of work to avoid human error.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    03-15-2015
    Location
    Canada
    MS-Off Ver
    Mac 2011
    Posts
    8

    Re: Using VBA to cross-reference class & teacher schedules

    Thanks for your help & putting up with my ignorance.

    Do the examples I've provided meet the need? There is no one particular "before" and "after" state. Each time I do an action with a drop down menu, I want the equivalent reaction on the corresponding schedule. I've coloured the homeroom class tabs orange and the rotary teachers' tabs green. If I pick a choice on an orange schedule, I need the matching green schedule to be verified and updated & vice versa.

  8. #8
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Using VBA to cross-reference class & teacher schedules

    Try this code. It belongs in the ThisWorkbook Object.

    It will automatically run if you change something in the Range C7:L16, and the color of the tab is that orange or green you used (xlThemeColorAccent3 and 6). That way you change change stuff on other sheets (MASTER, Teachers etc.) or outside the actual schedule slots without worrying about the code running.

    I recommend you continue to use a color scheme like that, because Workbook_SheetChange will run on ANY change on ANY sheet in the workbook unless given restrictions, and tab color is a handy restriction to use. Though we could come up with something else if need be.

    Please Login or Register  to view this content.
    Last edited by walruseggman; 03-16-2015 at 03:45 PM.

  9. #9
    Registered User
    Join Date
    03-15-2015
    Location
    Canada
    MS-Off Ver
    Mac 2011
    Posts
    8

    Re: Using VBA to cross-reference class & teacher schedules

    That is exactly what I needed. Thank you so very much!

  10. #10
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Using VBA to cross-reference class & teacher schedules

    Great! Please mark this thread as SOLVED.

    And any reputation points (the * in the lower left of my posts) is appreciated.

  11. #11
    Registered User
    Join Date
    03-15-2015
    Location
    Canada
    MS-Off Ver
    Mac 2011
    Posts
    8

    Re: Using VBA to cross-reference class & teacher schedules

    I need some help with debugging this now that I'm trying to put it into use.

    It works perfectly if I do not make any mistakes; however, if I insert information and then later try to delete it, I get a runtime error 9, subscript out of range.

    Since I'm going to need to enter information and then eventually will need to revise a lot of it, this creates a problem. How can I create it so that if I'm deleting the contents of a cell, the macro won't quit on me?

    Thanks so much in advance.


    Fairlawn Timetable Template Automated.xls

  12. #12
    Registered User
    Join Date
    03-15-2015
    Location
    Canada
    MS-Off Ver
    Mac 2011
    Posts
    8

    Re: Using VBA to cross-reference class & teacher schedules

    I added On Error Resume Next and that is helping. At least I am able to continue.

+ 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. Look up and cross reference
    By daparat in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-14-2015, 12:25 PM
  2. Formula for Teacher and Class timetable
    By deepanc in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-09-2014, 06:02 AM
  3. [SOLVED] Cross reference with multiple instances in reference data
    By Nick F in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-08-2013, 10:31 AM
  4. [SOLVED] Creating Individualised Schedules from Class Lists
    By ashleyd in forum Excel General
    Replies: 2
    Last Post: 07-06-2012, 06:26 PM
  5. Cross Reference
    By Lozza1610 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 03-25-2008, 06:50 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