Option Explicit
Private Sub Workbook_Open()
Dim Colonne As Long, k As Long, Cpt As Long
Dim Dte As String, JJ As String, Nom As String
Dim Tjour As String, Tnuit As String
Dte = InputBox("Entrer une date: (jj/mm/aaaa ou jj/mm/aa)", "Choix Date")
If IsDate(Dte) Then
JJ = InputBox("Entrer une période de travail: (jour ou nuit ou journee)", "Choix Période")
If UCase(JJ) <> "" Then
Select Case UCase(JJ)
Case Is = "JOUR"
Colonne = Day(Dte) * 2 + 1
If Sheets(MonthName(Month(Date))).Cells(11, Colonne).Value <> "0" Then
For k = 3 To 10
If Cells(k, Colonne) <> "" Then
Nom = Nom & Cells(k, 2) & Chr(10)
Cpt = Cpt + 1
End If
Next
MsgBox "Le " & Dte & " : il y a " & Cpt & " personne(s) qui travaille (ent) de " & JJ & Chr(10) & Nom
Exit Sub
Else
MsgBox "Personne"
Exit Sub
End If
Case Is = "NUIT"
Colonne = Day(Dte) * 2 + 2
If Sheets(MonthName(Month(Date))).Cells(11, Colonne).Value <> "0" Then
For k = 3 To 10
If Cells(k, Colonne) <> "" Then
Nom = Nom & Cells(k, 2) & Chr(10)
Cpt = Cpt + 1
End If
Next
MsgBox "Le " & Dte & " : il y a " & Cpt & " personne(s) qui travaille (ent) de " & JJ & Chr(10) & Nom
Exit Sub
Else
MsgBox "Personne"
Exit Sub
End If
Case Is = "JOURNEE"
Colonne = Day(Dte) * 2 + 1
If Sheets(MonthName(Month(Date))).Cells(11, Colonne).Value <> "0" _
Or Sheets(MonthName(Month(Date))).Cells(11, Colonne + 1).Value <> "0" Then
For k = 3 To 10
If Cells(k, Colonne) <> "" Then
Tjour = Tjour & Cells(k, 2) & ","
Cpt = Cpt + 1
End If
If Cells(k, Colonne + 1) <> "" Then
Tnuit = Tnuit & Cells(k, 2) & ","
Cpt = Cpt + 1
End If
Next
If Tjour <> "" And Tnuit <> "" Then
MsgBox "Le " & Dte & " : il y a " & Cpt & " personne(s) qui travaille (ent)" & vbCrLf & _
Tnuit & " la nuit" & vbCrLf & Tjour & " le jour"
Exit Sub
ElseIf Tjour <> "" And Tnuit = "" Then
MsgBox "Le " & Dte & " : il y a " & Cpt & " personne(s) qui travaille (ent) de jour." & vbCrLf & Tjour
Exit Sub
Else
MsgBox "Le " & Dte & " : il y a " & Cpt & " personne(s) qui travaille (ent) de nuit" & vbCrLf & Tnuit
Exit Sub
End If
Else
MsgBox "Personne"
Exit Sub
End If
End Select
End If
End If
End Sub