Hello! Not much stumps me in VBA but: How do you generate a list of work days based on a Shift Schedule that has more than one shift?
For example: Throughout the year I work 10 days on and 4 days off. My co worker works 7 Days on and 7 days off for 6 months.
I need to see the days of the year that correspond to each work day - for each worker. I know how to build my query to show the days, but I am truly stumped on how to generate the tbl_DaysOff.
For example:
1st Try:
2nd Try:
3rd Try:
For example: Throughout the year I work 10 days on and 4 days off. My co worker works 7 Days on and 7 days off for 6 months.
I need to see the days of the year that correspond to each work day - for each worker. I know how to build my query to show the days, but I am truly stumped on how to generate the tbl_DaysOff.
For example:
1st Try:
Code:
x = 0 r = 0 For iDate = StartDate To EndDate For iShiftOn = 1 To ShiftOn r = r + 0 MsgBox iShiftOn & ", Days ON: " & StartDate + iShiftOn + iShiftOff + x & ", " & r & "... and counting..." Next iShiftOn For iShiftOff = 1 To ShiftOff x = x + 1 MsgBox iShiftOff & ", Days OFF: " & StartDate + iShiftOn + iShiftOff + r & ", " & x & "... and counting..." Next iShiftOff Next iDate
Code:
x = 1 For iDate = StartDate To EndDate Switch = StartDate + 6 lastnext: For iShiftOn = 0 To ShiftOn - 1 If iDate = StartDate Then MsgBox "Daily insert (ON): " & iShiftOn + 1 & ", ON Dates: " & iDate + iShiftOn 'x Else x = 1 MsgBox "Daily insert (ON): " & iShiftOn + 1 & ", ON Dates: " & StartDate + 2: StartDate = StartDate + 1 x = x + 1: GoTo tr: End If If iShiftOn = 8 Then MsgBox "Switch: " & Switch + 1: x = x + 1: GoTo nexts: x = x + 1: tr: Next iShiftOn nexts: StartDate = Switch + 2: iDate = Switch + 1 For iShiftOff = 1 To ShiftOff MsgBox "Daily insert (OFF): " & iShiftOff & ", OFF Dates: " & StartDate + iShiftOff: 'StartDate = iDate ' + iShiftOff If iShiftOff = 7 Then StartDate = iDate + 6: GoTo nextss: 'MsgBox "Switch: " & StartDate + 1: GoTo nextss: Next iShiftOff x = 1 nextss: GoTo lastnext: Next iDate
Code:
For iDate = StartDate To EndDate For iShiftOn = 1 To ShiftOn iDailyInsrt = iDate + iShiftOn If iDailyInsrt = StartDate + ShiftOn Then MsgBox iDailyInsrt: GoTo NextiDate: If iShiftOn = ShiftOn Then MsgBox "Start: " & StartDate & ", Days ON/OFF: " & ShiftOn & "/" & ShiftOff & ", Date ON: " & iDate If iShiftOn = 7 Then MsgBox "Start: " & StartDate & ", Days ON/OFF: " & ShiftOn & "/" & ShiftOff & ", Date OFF: " & iDate For iShiftOff = 1 To ShiftOff MsgBox "Start: " & StartDate & ", Days ON/OFF: " & ShiftOn & "/" & ShiftOff & ", Switch: " & iDate Next iShiftOff NextiDate: Next iShiftOn Next iDate x = 0 For iDate = StartDate To EndDate x = x + 1 Switch = StartDate + 6 If x = 8 Then x = 1: If StartDate = StartDate Then MsgBox "Daily insert (ON): " & x & ", ON Dates: " & iDate If iDate = Switch Then MsgBox "Switch: " & Switch + 1: StartDate = Switch + 2: iDate = Switch + 1 For iShiftOff = 1 To 7 'ShiftOff iDate = Switch + iShiftOff MsgBox "Daily insert (OFF): " & iShiftOff & ", OFF Dates: " & iDate + iShiftOff: StartDate = iDate + iShiftOff If iShift = 7 Then MsgBox "Switch: " & Switch + 1: Next iShiftOff x = 0 End If Next iDate
Comment