Sub Calcul_moyenne()
Dim mini, calculA As Range, calculB As Range, nA&, nB&, n&, resu(), i&, n1&, n2&
mini = 5 'nombre minimum pour le calcul de moyenne
With Feuil1 'CodeName de la feuille
If .FilterMode Then .ShowAllData 'si la feuille est filtrée
On Error Resume Next 'si aucune SpecialCell
Set calculA = .Columns(6).SpecialCells(xlCellTypeFormulas, 1)
Set calculB = .Columns(7).SpecialCells(xlCellTypeFormulas, 1)
On Error GoTo 0
If Not calculA Is Nothing Then nA = calculA.Areas.Count
If Not calculB Is Nothing Then nB = calculB.Areas.Count
n = IIf(nA > nB, nA, nB)
If n Then
ReDim resu(1 To n, 1 To 3)
For i = 1 To nA
If calculA.Areas(i).Count >= mini Then n1 = n1 + 1: resu(n1, 2) = Application.Average(calculA.Areas(i))
Next
For i = 1 To nB
If calculB.Areas(i).Count >= mini Then n2 = n2 + 1: resu(n2, 3) = Application.Average(calculB.Areas(i))
Next
n = IIf(n1 > n2, n1, n2)
For i = 1 To n: resu(i, 1) = "Point " & i: Next
End If
'---restitution---
With .[K7] '1ère cellule de restitution, à adapter
If n Then
.Resize(n, 3) = resu
.Resize(n, 3).Borders.Weight = xlThin 'bordures
.Cells(1, 2).Resize(n, 2).Interior.Color = RGB(217, 225, 242) 'bleu
End If
.Offset(n).Resize(.Parent.Rows.Count - n - .Row + 1, 3).Delete xlUp 'RAZ en dessous
End With
End With
End Sub