You had a few $ signs in the wrong place and so when it was copied it wasn't referencing the correct cells
M6 should be:
=IF(OR($M$1=$K6,$M$1=$L6),"Off",IF(AND(M$5>=$D6,M$5<=($D6+$E$5),$D6<>""),IF($F6="",1,IF(AND(M$5>=$F6,M$5<=($F6+$F$5)),$F$4,IF($G6="",1,IF(AND(M$5>=$G6,M$5<($G6+$G$5)),$G$4,IF($H6="",1,IF(AND(M$5>=$H6,M$5<=($H6+$H$5)),$H$4,1)))))),"-"))
Then you copy that across and down
When you copy it to Column DE, you have to change references to M to DE
The again at Column GW etc