1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| Public Sub Calcul_Heure() '(mois As String)
'MsgBox "Nom de la feuille: " & mois
Dim dCoef, heures(), indexOuvriers, iCoef, nbCoef, tCoef
Set dCoef = Nothing
Set dCoef = CreateObject("Scripting.dictionary")
Set tCoef = CreateObject("Scripting.dictionary")
Set indexOuvriers = CreateObject("Scripting.dictionary")
With Worksheets("config")
nbligne = .Range("B2:B" & .Range("B" & .Rows.count).End(xlUp).Row).count
For Each c In .Range("A2:A" & .Range("A" & .Rows.count).End(xlUp).Row)
If Not dCoef.Exists(c.Value) Then dCoef.Add c.Value, c.Offset(0, 1).Value
Next c
For Each c In .Range("B2:B" & .Range("B" & .Rows.count).End(xlUp).Row)
If Not tCoef.Exists(c.Value) Then tCoef.Add c.Value, c.Offset(0, -1).Value
Next c
nbCoef = tCoef.count
'Set tCoef = Nothing
End With
With Worksheets("ouvriers")
nbligne = .Range("A2:A" & .Range("A" & .Rows.count).End(xlUp).Row).count
ReDim heures(nbligne, 4)
For i = 1 To nbligne
heures(i - 1, 0) = .Cells(i + 1, 1)
heures(i - 1, 1) = 0
heures(i - 1, 2) = 0
heures(i - 1, 3) = 0
heures(i - 1, 4) = 0
Next
End With
With Worksheets(ActiveSheet.Name)
Set iCoef = CreateObject("Scripting.dictionary")
For i = 1 To nbCoef
iCoef.Add .Cells(3, i).Value, i
Next
keys = iCoef.keys
Debug.Print "clé"
''Loop through Keys array
For i = 0 To UBound(keys)
Debug.Print "Key", i, keys(i)
Next
Dim Items()
''Get dictionary Items
Items = iCoef.Items
Debug.Print "Item"
''Loop through Items array
For i = 0 To UBound(Items)
Debug.Print "Item", i, Items(i)
Next
nbligne = .Range("E4:E" & .Range("E" & .Rows.count).End(xlUp).Row).count
For i = 4 To nbligne
indexOuvriers.Add .Cells(i, 5), i
Next
nbligne = .Range("E1:E" & .Range("E" & .Rows.count).End(xlUp).Row).count
nbcolonne = .Range("F3").SpecialCells(xlCellTypeLastCell).Column
Dim nbreHeures As Date
For cptouvrier = 4 To nbligne
For cptcolonne = 6 To nbcolonne
' Nous sommes un samedi ou dimanche
If IsEmpty(.Cells(3, cptcolonne).Value) Then
' Nous sommes samedi
If Left(.Cells(2, cptcolonne).Value, 4) = "same" Then
coefficient = dCoef("samedi")
nbreHeures = .Cells(cptouvrier, cptcolonne).Value * coefficient
heures(cptouvrier - 4, iCoef(coefficient)) = heures(cptouvrier - 4, iCoef(coefficient)) + nbreHeures
' Nous sommes dimanche
ElseIf Left(.Cells(2, cptcolonne).Value, 4) = "dima" Then
coefficient = dCoef("dimanche")
nbreHeures = .Cells(cptouvrier, cptcolonne).Value * coefficient
heures(cptouvrier - 4, iCoef(coefficient)) = heures(cptouvrier - 4, iCoef(coefficient)) + nbreHeures
End If
' Nous sommes un jour férié
ElseIf .Cells(3, cptcolonne).Value = "férié" Then
coefficient = dCoef("férié")
nbreHeures = .Cells(cptouvrier, cptcolonne).Value * coefficient
heures(cptouvrier - 4, iCoef(coefficient)) = heures(cptouvrier - 4, iCoef(coefficient)) + nbreHeures
'Nous sommes un jour normal
Else
coefficient = dCoef(CStr(.Cells(3, cptcolonne))) ' fallait spécifier sous forme de chaine car la Key est une chaine de caractère
nbreHeures = .Cells(cptouvrier, cptcolonne).Value * coefficient
heures(cptouvrier - 4, iCoef(coefficient)) = heures(cptouvrier - 4, iCoef(coefficient)) + nbreHeures
End If
Next
' il faut écrire le résultat dans les cellules de début
For i = 1 To nbCoef
.Cells(cptouvrier, i).Value = heures(cptouvrier - 4, i)
Next
Next
End With
End Sub |