Good day everyone,
I working on a big shift schedule where the crew are working 4 days by 4 days.
The Shift has a pattern like : N N N N O O O O D D D D, N for Night, D for Day & O for Off.
other shift has the opposite pattern like: D D D D O O O O N N N N
what i need is a macro that help me to generate and auto fill the rest of the cells of the month or maybe the year if I only typed one letter in any cell
WHAT I THINKING ABOUT IS THE FOLLOWING:
let say i wrote KN3 which mean "START FROM THE 3 NIGHT"; the rest of cell have to continue the pattern like: N N O O O O D D D D N N N N .....
my code is
[COLOR=#333333]Sub ForEach_Loop()[/COLOR]
Dim cell As Range
Dim mystring1 As String
Dim mystring2 As String
Dim mystring3 As String
'How many cells in worksheet have values in them?
For Each cell In Sheets("SHIFT SCHEDULE").UsedRange.Cells
If UCase(cell.Value) = "KN1" Then
mystring1 = String(1, "N")
Range("List!E12") = mystring1
Range("F13:I13") = Application.WorksheetFunction.Rept(Range("List!E12"), 1)
' Repeating O
mystring2 = String(1, "O")
Range("List!E13") = mystring2
Range("J13:M13") = Application.WorksheetFunction.Rept(Range("List!E13"), 1)
' Repeating D
mystring3 = String(1, "D")
Range("List!E14") = mystring3
Range("N13:Q13") = Application.WorksheetFunction.Rept(Range("List!E14"), 1)
' Repeating O
mystring2 = String(1, "O")
Range("List!E15") = mystring2
Range("R13:U13") = Application.WorksheetFunction.Rept(Range("List!E15"), 1)
End If
Next cell
[COLOR=#333333]End Sub[/COLOR][COLOR=#333333][/COLOR]
Display More
The problem that I facing now is whenever I typed "KN1" in "SHIFT SCHEDULE" sheet, The pattren " N N N N ...." is being repeated in "list" sheet
Sheet 1= "SHIFT SCHEDULE" , Sheet 2 = list
Also, instead of specifying the Range like I did above (e.g. Range (F13:I13) )
I want it to be a general column/row range.
attached the my Excel sheet.
regards.