I'm a noob at VB, and totally self taught. The following code is for a time sheet, which automatically fills in the shift based on the date. There are 4 possible schedule patterns, Day Shift, Night Shift, Daywork and Daywork Training. It looks on a hidden sheet that has the shift pattern in the cells and the shift type represented by:
D = Day shift
N= Night Shift
DW = Daywork (8 hr Mon-Fri)
DT = Daywork Training
They all work except for the final one (Daywork Training), which fills in ALL the slots on the timesheet, as if all shifts were selected. I'm pulling my hair out, because it's the exact same IF-THEN format as the other schedules, but it doesn't work. Any help is appreciated. (I know there are probably more efficient ways to write this code, bbut like I said, I'm a self taught noob)
I hope I explained this well enough.
Sub PlaceShiftHours()
Dim ShiftLetter, DatePos
On Error Resume Next
If Cells(4, 19).Value = "Letter A" Then ShiftLetter = 1
If Cells(4, 19).Value = "Letter B" Then ShiftLetter = 2
If Cells(4, 19).Value = "Letter C" Then ShiftLetter = 3
If Cells(4, 19).Value = "Letter D" Then ShiftLetter = 4
If Cells(4, 19).Value = "Letter A/B" Then ShiftLetter = 5
If Cells(4, 19).Value = "Letter C/D" Then ShiftLetter = 6
If Cells(4, 19).Value = "Daywork" Then ShiftLetter = 7
If Cells(4, 19).Value = "Training" Then ShiftLetter = 8
ClearCells
For X = 5 To 18
WorkDate = Cells(14, X).Value
DatePos = ((WorkDate - 41617) Mod 28) + 1
If ActiveWorkbook.Worksheets("Shifts").Cells(DatePos, ShiftLetter).Value = "D" Then
ActiveWorkbook.Worksheets("TimeSheet").Cells(28, X).Value = 8
ActiveWorkbook.Worksheets("TimeSheet").Cells(29, X).Value = 4
ActiveWorkbook.Worksheets("TimeSheet").Cells(15, X).Value = [VLOOKUP(TimeSheet!I3, OperatorArray, 4)]
End If
If ActiveWorkbook.Worksheets("Shifts").Cells(DatePos, ShiftLetter).Value = "N" Then
ActiveWorkbook.Worksheets("TimeSheet").Cells(32, X).Value = 8
ActiveWorkbook.Worksheets("TimeSheet").Cells(33, X).Value = 4
ActiveWorkbook.Worksheets("TimeSheet").Cells(15, X).Value = [VLOOKUP(TimeSheet!I3, OperatorArray, 4)]
End If
If ActiveWorkbook.Worksheets("Shifts").Cells(DatePos, ShiftLetter).Value = "DW" Then
ActiveWorkbook.Worksheets("TimeSheet").Cells(16, X).Value = 8
ActiveWorkbook.Worksheets("TimeSheet").Cells(15, X).Value = [VLOOKUP(TimeSheet!I3, OperatorArray, 4)]
End If
If ActiveWorkbook.Worksheets("Shifts").Cells(DatePos, ShiftLetter).Value = "DT" Then
ActiveWorkbook.Worksheets("TimeSheet").Cells(24, X).Value = 8
ActiveWorkbook.Worksheets("TimeSheet").Cells(15, X).Value = [VLOOKUP(TimeSheet!I3, OperatorArray, 4)]
End If
Next X
End Sub
Bookmarks