Bonsoir le forum,
que d'étoiles sur ce sujet! 8)
Je ne pouvais pas laisser VBA sans défenseur!
En supposant une ligne d'en-tête dans ton fichier, un clic en [C1] déclenche le calcul qui s'affiche, sans précision de ta part, dans une MsgBox.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'
Dim tTab
Dim tAlpha()
'
If Not Intersect(Target, Range("C1")) Is Nothing Then
Application.ScreenUpdating = False
'
iRow = Range("B" & Rows.Count).End(xlUp).Row
iCol = Cells(1, Columns.Count).End(xlToLeft).Column
sCol = Split(Columns(iCol).Address(ColumnAbsolute:=False), ":")(1)
iFlag = DateDiff("d", Cells(2, 2), Date) + 2
Range("A2:" & sCol & iRow).Sort key1:=Range("C2"), order1:=xlAscending, Orientation:=xlTopToBottom
tTab = Range("C2:C" & iRow)
Range("A2:" & sCol & iRow).Sort key1:=Range("B2"), order1:=xlAscending, Orientation:=xlTopToBottom
iIdx = 1
ReDim Preserve tAlpha(iIdx)
'
For x = 1 To UBound(tTab)
If tAlpha(iIdx - 1) <> tTab(x, 1) Then
If x > 1 Then iIdx = iIdx + 1
ReDim Preserve tAlpha(iIdx)
tAlpha(iIdx - 1) = tTab(x, 1)
Cells(1, iCol + 100).FormulaLocal = "=NB.SI(C2:C" & CInt(iFlag) & ";""" & tAlpha(iIdx - 1) & """)"
sFlag = sFlag & tAlpha(iIdx - 1) & " - " & Cells(1, iCol + 100) & Chr(10)
End If
Next
'
MsgBox "Totaux au " & Date & Chr(10) & Chr(10) & sFlag
Application.ScreenUpdating = True
End If
'
End Sub
Pour le plaisir du code!
A+