Function festivo(valore As String) As Boolean If Weekday(CDate(Val(valore) & " " & ActiveSheet.Cells(4, 1).Formula)) = 1 Then festivo = True End FunctionCon questo, individuo nel Calendario quali sono i giorni festivi (per il momento le domeniche, ma la funzione va ampliata a seconda dei giorni festivi diversi dalle domeniche), e vi inserisco anche il reparto che fa il turno festivo.
Mi sembra adeguato inserire il reparto diverso da quello che fa la notte.
La funzione completa ha questo codice:
Dim reparti(1) As String Dim n As Integer reparti(0) = "CAR" reparti(1) = "MED" n = Int(Rnd() * 2) Range("Reparto").Cells(1, 1).Formula = reparti(n) For k = 2 To Range("Reparto").Rows.Count If n = 0 Then n = 1 Else n = 0 End If Range("Reparto").Cells(k, 1).Formula = reparti(n) If festivo(Range("Reparto").Cells(k, 1).Offset(0, -2).Formula) Then If Range("Reparto").Cells(k, 1).Formula = "MED" Then Range("Reparto").Cells(k, 1).Formula = "CAR - MED" Else Range("Reparto").Cells(k, 1).Formula = "MED - CAR" End If End If Next kE questo è il risultato:
Nessun commento:
Posta un commento