Compléter un code VBA
H
Bonjour, je veux aider à compléter ce code afin que je puisse trouver la somme des cellules de TOTAL-a et TOTAL_b. Voici le fichier
Il est possible d'incrémenter les lignes, le code doit être exécuté à condition que l'instruction TOTAL_b+t existe
Sub SUM()
Dim LastRow As Long, i As Long, X As Long, MH As Long
Dim ln&
Application.DisplayAlerts = False
X = 1
With ThisWorkbook.Worksheets("FEUIL1")
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
Range("C" & LastRow & ":c" & LastRow).ClearContents
For i = 1 To LastRow
If .Range("b" & i).Value = "total-A" Or .Range("b" & i).Value = "total-B" Or .Range("b" & i).Value = "total-T" Then
MH = i - 1
.Range("C" & i).Value = Application.SUM(.Range(.Cells(X, 3), .Cells(MH, 3)))
.Range("C" & LastRow) = .Range("C" & LastRow) + .Range("C" & i)
X = i + 1
Application.DisplayAlerts = True
End If
Next i
End With
End SubBonjour,
Pensez à faire une petite présentation ici --> https://forum.excel-pratique.com/presentations. Ce sera le bienvenu
Nul besoin de vous encombrer avec un code VBA pour faire cela. La formule Sous.Total vous donne le résultat attendu.
- En C5 --> mettez =SOUS.TOTAL(9;C2:C4)
- En C11--> mettez =SOUS.TOTAL(9;C6:C10)
- En C12 --> mettez =SOUS.TOTAL(9;C2:C11)
- En C19 --> Mettez =SOUS.TOTAL(9;C2:C18)
Si ok -->
NB : pourquoi utilisez vous l'icône citation ("") pour écrire votre demande ??
Du coup on ne voit pas ce que comporte votre demande ici --> https://forum.excel-pratique.com/membre/100544
Cordialement