Problème de codage sur VBA

Bonjour,

Je comprends pas pourquoi il prend pas en compte ma dernière ligne de codage... Cells(j, 18) = somme

Sub testsia()

Sheets("SUIVTRANS EN COURS").Activate

    Derligne = Range("A" & Rows.Count).End(xlUp).Row
    Range("M3:M" & Derligne).ClearContents

    Tablo = Range("J3", "K" & Range("K" & Rows.Count).End(xlUp).Row)

    For j = 3 To Derligne

     somme = 0
        codeP = Cells(j, "H")
        For i = LBound(Tablo, 1) To UBound(Tablo, 1)
            If Cells(j, "J") = Tablo(i, 1) Then
                If Cells(i + 1, "H") <> codeP Then
                    GoTo pasDeCommentaire
                Else
                    somme = somme + CDbl(Tablo(i, 2))
                End If
            End If

        Next i
        [b][u]Cells(j, 18) = somme[/u][/b]
         Next j
End Sub

Bonjour,

vérifier le contenu de ta variable Derligne

Ma derligne est bonne :/

En fait ma macro marche parfaitement, sauf que j'ai du enlevé le "With" Sheets... Car quand tu crée un bouton pour lancer ta macro elle reconnait pas les With donc j'ai du enlever tous les With et du coup ca bloque

bonjour,

rien compris à ce que tu dis.

mets ton fichier avec la macro qui fonctionne parfaitement, mais qui ne fonctionne pas ...

Bonjour KOBD, h2so4,

je propose ce code VBA (à tester) :

Option Explicit

Sub testsia()
  Dim Tablo, codeP$, somme#, dlig&, n&, i&, j&
  Worksheets("SUIVTRANS EN COURS").Select

  dlig = Cells(Rows.Count, "M").End(xlUp).Row
  If dlig > 2 Then Range("M3:M" & dlig).ClearContents

  dlig = Cells(Rows.Count, "K").End(xlUp).Row
  Tablo = Range("J3:K" & dlig): n = dlig - 2

  dlig = Cells(Rows.Count, "A").End(xlUp).Row

  For i = 3 To dlig
    codeP = Cells(i, "H"): somme = 0
    For j = 1 To n
      If Cells(i, "J") = Tablo(j, 1) Then
        If Cells(j + 1, "H") = codeP Then _
          somme = somme + CDbl(Tablo(j, 2))
      End If
    Next j
    Cells(i, "R") = somme
  Next i

End Sub

dhany

Rechercher des sujets similaires à "probleme codage vba"