Sub Repartition(ncol%, nvide&, 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
'---restitution---
With Feuil2.[A2] 'CodeName
If n Then .Resize(n, 6) = restrep
.Offset(n).Resize(Rows.Count - n - .Row + 1, 6).ClearContents
.EntireColumn.Resize(, 6).AutoFit 'ajustement largeur
With .Parent.UsedRange: End With 'actualise la barre de défilement
End With
End Sub