I am writing a VBA code to double check and make sure I don't double book instructors or classrooms. My code is below.
For each WeekDay/Period combination it checks the schedule and every time a T or R etc and 1 or 2 etc match up with the WeekDay/Period combination I should get a 1. The function does exactly what I want it to for every case except for the second part of a double(i.e. R when LabDay is "TR" or 2 for LabPeriod is "12") I've tried
but I don't get a 1 when I should. I do get a 1 for the first part (i.e. T when LabDay is "TR" or 1 for LabPeriod is "12"). The WeekDay/Period combinations are in separate cells so the fact that it catches the left value shouldn't have an impact on it catching the right value.
I have tried setting up variables and breaking the code to try and see if there is a format mismatch somewhere. (i.e. a number being compared to a string) but I haven't been able to find the problem. I'm relatively new to VBA so I'm hoping another set of more experienced eyes will be able to see the problem easily.
Any help would be appreciated.
Lucky
Possible inputs:
ClassDay1,2,3 or WeekDay could be "M","T","W","R","F"
LabDay could be "T","R","TR","WF"
ClassPeriod or Period could be "1","2","3","4","5","6"
LabPeriod could be "12","34","56"
For each WeekDay/Period combination it checks the schedule and every time a T or R etc and 1 or 2 etc match up with the WeekDay/Period combination I should get a 1. The function does exactly what I want it to for every case except for the second part of a double(i.e. R when LabDay is "TR" or 2 for LabPeriod is "12") I've tried
Code:
Right(LabPeriod,1) = Period
I have tried setting up variables and breaking the code to try and see if there is a format mismatch somewhere. (i.e. a number being compared to a string) but I haven't been able to find the problem. I'm relatively new to VBA so I'm hoping another set of more experienced eyes will be able to see the problem easily.
Any help would be appreciated.
Lucky
Possible inputs:
ClassDay1,2,3 or WeekDay could be "M","T","W","R","F"
LabDay could be "T","R","TR","WF"
ClassPeriod or Period could be "1","2","3","4","5","6"
LabPeriod could be "12","34","56"
Code:
Function PeriodCalc(ClassDay1, ClassDay2, ClassDay3, LabDay, WeekDay, ClassPeriod, LabPeriod, Period)
If ClassDay1 = WeekDay Or ClassDay2 = WeekDay Or ClassDay3 = WeekDay Or Left(LabDay, 1) = WeekDay Or Right(LabDay, 1) = WeekDay Then
If ClassPeriod = Period Or Left(LabPeriod, 1) = Period Or Right(LabPeriod, 1) = Period Then
PeriodCalc = 1
End If
Else
PeriodCalc = 0
End If
End Function