Aide à la modification du code VBA

Bonjour à tous...🤝 J'ai un problème pour modifier un code pour calculer la somme d'un certain domaine. J'ai réussi à en créer une partie, mais je n'ai pas pu continuer. Pouvez-vous m'aider s'il vous plaît. C'est le code que j'utilise pour calculer certains chiffres sous condition.. Je voudrais, après avoir terminé, obtenir la somme des enceintes en un seul chiffre, comme indiqué dans le fichier joint.

16test1.xlsm (18.58 Ko)
Sub SUM()
    Dim LastRow As Long, i As Long, X As Long, MH As Long
    Application.DisplayAlerts = False
    X = 1
    With ThisWorkbook.Worksheets("FEUIL1")
    LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row + 1
    For i = 1 To LastRow
    If .Range("b" & i).Value = "toutal-A" Or .Range("b" & i).Value = "toutal-B" Then
      MH = i - 1

     .Range("C" & i).Value = Application.SUM(.Range(.Cells(X, 3), .Cells(MH, 3)))
     .Range("D" & i).Value = Application.SUM(.Range(.Cells(X, 4), .Cells(MH, 4)))
      .Range("E" & i).Value = Application.SUM(.Range(.Cells(X, 5), .Cells(MH, 5)))

      X = i + 1
      Application.DisplayAlerts = True

            End If

        Next i

    End With

End Sub

Bonjour

Un essai à tester. Te convient-il ?

9test1-v1.xlsm (19.32 Ko)

Bye !

Merci, mais il y a un problème en ré-appuyant, la somme descend, ce qui devrait être dynamique

Nouvelle version

15test1-v2.xlsm (19.60 Ko)

Bye :!

Merci beaucoup, c'est ce dont j'ai besoin

Rechercher des sujets similaires à "aide modification code vba"