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
| ' Récapitulatif des horaires
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rg As Range
Dim c As Range
Dim Deb As Range
Const DateLigne1 = "C16:Q16"
Const DateLigne2 = "C21:R21"
Const DateLigneRecap = "C67:P67"
Set Rg = Application.Union(Range(DateLigne1), Range(DateLigne2))
'Si on change un horaire
If Not Intersect(Target, Rg) Is Nothing Then
'Dans la fenêtre VBA, sélectionner Outils, Références et cocher Microsoft Scripting Runtime
Dim Dico As Object
Set Dico = CreateObject("scripting.dictionary")
'Pour chaque cellule sur le calendrier
For Each c In Rg
'Si la cellule n'est pas vide
If IsEmpty(c) = False Then 'And Val(c) <> 0
If Not Dico.Exists(c.Value) Then
'Si la clé n'existe pas affecte la première valeur (=1) c'est initialisation
Dico(c.Value) = 1
Else
'Si la clé existe déjà : on ajoute un pour les compter
Dico(c.Value) = Dico(c.Value) + 1
End If
End If
Next c
'Réalise un tri
Dim bas()
Dim t
ReDim bas(1 To Dico.Count)
Dim i As Integer
i = 1
For Each t In Dico.keys
bas(i) = t
i = i + 1
Next t
Call Tri(bas, 1, Dico.Count)
'--- Place les résultats dans la bonne ligne
Set Deb = Sheets("essai").Range(DateLigneRecap).Resize(1, 1)
For i = 1 To UBound(bas())
Deb.Offset(0, i).Value = bas(i)
Next i
'--- Détruit les variables
Set Dico = Nothing
Set Rg = Nothing
Set Deb = Nothing
End If
End Sub
Sub Tri(a, Gauche, Droit) ' Tri type "Quick sort"
ref = a((Gauche + Droit) \ 2)
G = Gauche
D = Droit
Do
Do While a(G) < ref
G = G + 1
Loop
Do While ref < a(D)
D = D - 1
Loop
If G <= D Then
'Permute
temp = a(G)
a(G) = a(D)
a(D) = temp
G = G + 1
D = D - 1
End If
Loop While G <= D
If G < Droit Then Call Tri(a, G, Droit)
If Gauche < D Then Call Tri(a, Gauche, D)
End Sub |
Partager