'per Foglio3 - con straordinari e Riposo Sub Turnaz_Riposo() Dim matrix(1 To 22), extract(1 To 22), vt(1 To 8) Dim i As Long, j As Long, k As Long, h As Long, w As Long, numcas As Integer Dim fabb_so, fabb_rep, fabb_dp, fabb, max '----------------------------------------------- pezzo aggiunto Dim ripeti As Integer Dim uRow As Integer Application.EnableEvents = False Application.ScreenUpdating = False For ripeti = 1 To 30 '------------------------------------------------ Range("B5:W26").ClearContents For i = 1 To 22 matrix(i) = i ': extract(i) = i Next i 'inserimento turno1 SO For i = 2 To 18 Step 3 For j = 1 To 22 extract(j) = j Next j fabb = Cells(37, i) For k = 1 To fabb dinuovo: Randomize numcas = Int((22 - 1 + 1) * Rnd + 1) For h = 1 To 22 'controllo se già stato estratto If extract(numcas) = 0 Then GoTo dinuovo 'altrimenti ne estraggo un altro Else extract(numcas) = 0 Exit For End If Next h numcas = numcas + 4 max = Cells(27, i) If max < fabb Then Cells(numcas, i) = 1 End If Next k Next i 'inserimento turno2 SO+DP+RR For i = 3 To 18 Step 3 For j = 5 To 26 If Cells(j, i - 1) = 1 Then matrix(j - 4) = 1 extract(j - 4) = j - 4 Next j fabb = Cells(37, i) fabb_so = Cells(31, i) For k = 1 To fabb ancora: Randomize numcas = Int((22 - 1 + 1) * Rnd + 1) For h = 1 To 22 'controllo se già stato estratto If extract(numcas) = 0 Then GoTo ancora 'altrimenti ne estraggo un altro Else extract(numcas) = 0 Exit For End If Next h numcas = numcas + 4 max = Cells(27, i) If max = 0 Then Cells(numcas, i) = 3 ElseIf max > 0 Then Cells(numcas, i) = 1 End If If max = fabb_so Then Cells(numcas, i) = 4 End If Next k Next i 'inserimento turno REP (domenica esclusa) For i = 4 To 19 Step 3 For j = 5 To 26 If Cells(j, i - 1) = 1 Or Cells(j, i - 2) = 1 Or _ Cells(j, i - 1) = 3 Then matrix(j - 4) = 1 'extract(j - 4) = j - 4 Next j fabb = Cells(37, i) For k = 1 To fabb turno2: Randomize numcas = Int((22 - 1 + 1) * Rnd + 1) For h = 1 To 22 'controllo se già stato estratto If extract(numcas) = 0 Then GoTo turno2 'altrimenti ne estraggo un altro Else extract(numcas) = 0 Exit For End If Next h numcas = numcas + 4 max = Cells(27, i) If max < fabb Then Cells(numcas, i) = 2 End If Next k Next i 'inserimento turnoDOM (domenica) For i = 20 To 21 For j = 5 To 26 If Cells(j, i - 1) = 1 Or Cells(j, i - 2) = 1 Or _ Cells(j, i - 1) = 3 Then matrix(j - 4) = 1 extract(j - 4) = j - 4 Next j fabb = Cells(37, i) For k = 1 To fabb turnoDOM: Randomize numcas = Int((22 - 1 + 1) * Rnd + 1) For h = 1 To 22 'controllo se già stato estratto If extract(numcas) = 0 Then GoTo turnoDOM 'altrimenti ne estraggo un altro Else extract(numcas) = 0 Exit For End If Next h numcas = numcas + 4 max = Cells(27, i) If max < fabb Then Cells(numcas, i) = 2 End If Next k Next i j = 0 For i = 5 To 26 If Cells(i, 5) = "" Then j = j + 1: vt(j) = i End If Next i Randomize numcas = Int((j - 1 + 1) * Rnd + 1) Cells(vt(numcas), 5) = 1 Application.EnableEvents = True Calc_Ore_Operatore Range("W5:Y26").ClearContents cerca_elemento '--------------------------------------- pezzo aggiunto uRow = Sheets("Risultati").Cells(Rows.Count, 1).End(xlUp).Row + 1 Sheets("Risultati").Cells(uRow, 1) = Sheets("Foglio3").Cells(27, "Z") Next ripeti Application.ScreenUpdating = True '---------------------------------------- End Sub |