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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
Sub SousTotauxCours(affiche As Boolean)
Dim pasplus&, t, nlig&, rest(), soustotal(), total(), i&, num&, n&, j%, v, test As Boolean
pasplus = pas 'pour incrémentation
'---initialisation---
With [A1].CurrentRegion
t = .Resize(, ncol) 'matrice, plus rapide
nlig = .Rows.Count
ReDim rest(1 To nlig + Int(nlig / pas) + nvide + 2, 1 To ncol)
End With
ReDim soustotal(1 To ncol)
ReDim total(1 To ncol)
'---remplissage du tableau rest---
For i = 4 To nlig
If InStr(LCase(t(i, 2)), "total") = 0 Then
num = num + 1
n = n + 1
For j = 1 To ncol
v = t(i, j)
If v <> "" Then
rest(n, j) = v
If j > 2 Then
If j Mod 2 Then 'colonnes C E G
test = False
test = i = 4 Or t(i, 2) <> ""
If i > 1 Then test = test Or t(i - 1, j) = ""
If test Then soustotal(j) = soustotal(j) + 1
Else 'colonnes D F H
soustotal(j) = soustotal(j) + 1
End If
End If
End If
Next j
If affiche And num = pasplus Then
If i < nlig Then If t(i + 1, 2) = "" Then pasplus = pasplus + 1: GoTo 1
n = n + 1
rest(n, 2) = "Sous-total"
For j = 3 To ncol
rest(n, j) = soustotal(j)
total(j) = total(j) + soustotal(j)
Next j
ReDim soustotal(1 To ncol) 'RAZ
pasplus = pas: num = 0
End If
End If
1 Next i
'---les 2 dernières lignes du tableau rest---
If affiche Then
If n Then
If rest(n, 2) <> "Sous-total" Then
n = n + 1
rest(n, 2) = "Sous-total"
For j = 3 To ncol
rest(n, j) = soustotal(j)
total(j) = total(j) + soustotal(j)
Next j
End If
End If
n = n + nvide + 1
rest(n, 2) = "Total"
For j = 3 To ncol
rest(n, j) = total(j)
Next j
End If
'---restitution---
If n Then [A4].Resize(n, ncol) = rest
Rows(n + 4 & ":" & Rows.Count).ClearContents
With Me.UsedRange: End With 'actualise la barre de défilement
Repartition affiche, rest(), n 'appelle la macro
End Sub
Sub Repartition(affiche As Boolean, rest(), n&)
Dim domaine, restrep(), i&, v$, j%, x$, y$, subvention&
domaine = [A2].Resize(, ncol) 'à adapter éventuellement
ReDim restrep(1 To UBound(rest), 1 To 6)
ReDim total(1 To 5)
For i = 1 To IIf(affiche, n - nvide - 1, n)
v = rest(i, 2)
If v <> "Sous-total" Then
If v <> "" Then
v = v & " " 's'il n'y a pas de prénom
For j = 1 To Len(v) 'recherche du prénom
x = Mid(v, j, 1): y = Mid(v, j + 1, 1)
If x = UCase(x) And y = LCase(y) And y <> " " _
And y <> "-" And y <> "'" Then Exit For
Next j
restrep(i, 1) = Trim(Left(v, j - 1)) 'nom
restrep(i, 2) = Trim(Mid(v, j)) 'prénom
ElseIf i > 1 Then
restrep(i, 1) = restrep(i - 1, 1) 'copie le nom
restrep(i, 2) = restrep(i - 1, 2) 'copie le prénom
End If
For j = 3 To ncol Step 2
If rest(i, j) <> "" Then
restrep(i, 3) = rest(i, j) 'cours
restrep(i, 6) = domaine(1, j) 'domaine
v = rest(i, j + 1)
j = InStr(v & "(", "(")
restrep(i, 4) = Left(v, j - 1) 'deg
restrep(i, 5) = Val(Mid(v, j + 1)) 'subvention
subvention = subvention + restrep(i, 5)
Exit For
End If
Next j
Else
restrep(i, 1) = v 'Sous-total
For j = 3 To ncol Step 2
restrep(i, 3) = restrep(i, 3) + rest(i, j)
restrep(i, 4) = restrep(i, 4) + rest(i, j + 1)
Next j
restrep(i, 5) = subvention: subvention = 0
For j = 3 To 5
total(j) = total(j) + restrep(i, j)
Next j
End If
Next i
'---dernière ligne---
If affiche Then
restrep(n, 1) = "Total": restrep(n, 3) = total(3)
restrep(n, 4) = total(4): restrep(n, 5) = total(5)
End If
'------
With Feuil2 'CodeName
If n Then .[A3].Resize(n, 6) = restrep
.Rows(n + 3 & ":" & .Rows.Count).ClearContents
.Columns.Resize(, 6).AutoFit 'ajuste la largeur
.CommandButton1.Width = .[A1:B1].Width
With .UsedRange: End With 'actualise la barre de défilement
End With
End Sub |
Partager