Problème code

Bonjour

je ne comprend pas pourquoi mon code ne veux pas marcher

il me fait erreur 13 sur la ligne 13

Sub MONTANT()

    Dim Date_Souscription_Adhésion As Range, Statut_Technique_Sinistre As Range
    Dim Montant_Ind_Principale As Range
    Dim dernligne As Long
    Dim i, j, k As Integer
    Dim a, b, c, d, e, somme As Integer
    Dim s As String

    With Worksheets("Sinistre")
        dernligne = .Range("A" & .Rows.Count).End(xlUp).Row
        Set Date_Souscription_Adhésion = .Range("G2:G" & dernligne)
        Set Montant_Ind_Principale = .Range("AB2:AB" & dernligne)
        Set Statut_Technique_Sinistre = .Range("V2:V" & dernligne)
    End With

    For i = 2 To dernligne
        s = Cells(i, "V").Value
        If s = "En cours" Or " En attente de prescription" Or " Terminé - accepté" Or " Terminé sans suite" Or " Annulé Gestion" Then
            Sheets("Feuil4").Cells(i, 6).Value = WorksheetFunction.Sum(Montant_Ind_Principale)
        End If
    Next i

End Sub

merci de votre aide


voici un petit fichier

6exple.xlsm (73.85 Ko)

Bonjour ,

ton code :

dernligne = .Range("A" & .Rows.Count).End(xlUp).Row
        Set Date_Souscription_Adhésion = .Range("G2:G" & dernligne)
        Set Montant_Ind_Principale = .Range("AB2:AB" & dernligne)
        Set Statut_Technique_Sinistre = .Range("V2:V" & dernligne)

essaye sans le point .Range --> Range(.....

sinon tu précises avant le point sur quel feuille tu es : ThisWorkbook.Sheets("Non de la feuille").Range(........

sa me fait toujours la même erreur pour la condition du s

Teste

 s = Cells(i, 22).Value

au lieu de

 s = Cells(i, "V").Value

il m'accepte toujours pas

If s = "En cours" Or " En attente de prescription" Or " Terminé - accepté" Or " Terminé sans suite" Or " Annulé Gestion" Then

re,

tout d'avoir regard ce que tu écris et respect la typologie ,

les erreurs d'incompatibilité c'est normal mais s = après chaque or

tu as corrigé pour YEAR( cells(...))?????? grosse erreur tu dois le texte en date

super sa marche merciiii

mais sa ne me calcule pas avec la condition

il me calcul la somme de la colonne entiere?

Bonjour aude21,

Première quand j'ai regardé ton fichier xlm, j'ai quitté directement, essaye d'être ordonner.

deuxièmement : le code que tu as fait je ne sais pas qu'il fait sur la feuil1, si tu prenais le temps d'expliquer ce que tu souhaites obtenir, nous pourrons t'aider plus facilement,

dernièrement prend le temps de nommée tes modules feuilles et outils

à te lire

merci de ta patience medas

voila j'ai refait le fichier et réajuster le code

j'aimerais avoir la somme de la colonne montant indemnité principale une fois que la condition if est effectuer

dans mon exple je devrais avoir 6430,75 mais il me met la somme total de la colonne sans respecter la condition (7466.33)

voici le code

Sub MONTANT_INDEMNITE_PRINCIPALE()

    Dim Date_Souscription_Adhésion As Range, Statut_Technique_Sinistre As Range
    Dim Montant_Ind_Principale As Range
    Dim dernligne As Long
    Dim i As Integer
    Dim s As String

    With Worksheets("Feuil1")
        dernligne = ThisWorkbook.Sheets("Feuil1").Range("A" & .Rows.Count).End(xlUp).Row
        Set Date_Souscription_Adhésion = ThisWorkbook.Sheets("Feuil1").Range("B2:B" & dernligne)
        Set Montant_Ind_Principale = ThisWorkbook.Sheets("Feuil1").Range("E2:E" & dernligne)
        Set Statut_Technique_Sinistre = ThisWorkbook.Sheets("Feuil1").Range("D2:D" & dernligne)
    End With

    For i = 2 To dernligne
        s = Cells(i, 4).Value
      ' If s = "En cours" Or s = " En attente de prescription" Or s = " Terminé - accepté" Or s = " Terminé sans suite" Or s = " Annulé Gestion" Then
        If s <> "Terminé - Refusé après instruction" Then
            Sheets("Feuil2").Cells(i, 2).Value = WorksheetFunction.Sum(Montant_Ind_Principale)
       End If
    Next i

End Sub
5exple.xlsm (55.05 Ko)

s=Cells(i,"V").value te retourne rien.

j'ai rien dit

regarde le fichier

11exple-4v1.xlsm (48.23 Ko)

si mais sa me renvoie la somme de tt la colonne mais moi je veux qu'il me fasse la somme après que la condition soit respecté

si j'ai bien compris

à te lire,

??

sur la premiere page j'ai marqué regarde ce fichier j'ai joints ton fichier

c'est presque sa

mais moi je veux la somme des montant indemnité principale pour dans lexple ici

nov 2015=652

dec 2015 =1111.2

janv 2016=3681

fev 2016=985

je prend mon fichier excel je filtre par rapport au statut technique (jenleve refusé-terminé apres instruction)

je filtre paar rapport la date d'adhesion (nov 2015) je vais dans la colonne montant indemnité principale et je vois la somme

c'est cette somme que je veux

le principe reste le même :

je te le fais en mode français pour tu le fasse sur ta feuille vba.

pour i = 1 jusqu'à dernière ligne

si ma celllule = nov2015 alors

somme pour nov2015 = somme + cellule(i,"E")

sinon si ma celulle = dec2015 alors

fin si

fin pour

si tu as du mal à le réaliser montre moi ton avancement je te guiderai

c'etais un exple mais dans le vrai fichier il ya de mars 2013 a fevrier 2017

je dois faire comme sa pour tous?

Sub MONTANT_INDEMNITE_PRINCIPALE()

    Dim Date_Souscription_Adhésion As Range, Statut_Technique_Sinistre As Range
    Dim Montant_Ind_Principale As Range
    Dim dernligne As Long
    Dim i As Integer
    Dim s As String
    Dim montant As String
    Dim tt As Double

    With Worksheets("Feuil1")
        dernligne = ThisWorkbook.Sheets("Feuil1").Range("A" & .Rows.Count).End(xlUp).Row
        Set Date_Souscription_Adhésion = ThisWorkbook.Sheets("Feuil1").Range("B2:B" & dernligne)
        Set Montant_Ind_Principale = ThisWorkbook.Sheets("Feuil1").Range("E2:E" & dernligne)
        Set Statut_Technique_Sinistre = ThisWorkbook.Sheets("Feuil1").Range("D2:D" & dernligne)
    End With

    For i = 2 To dernligne
        s = Cells(i, 4).Value
        montant = Cells(i, 5).Value
      ' If s = "En cours" Or s = " En attente de prescription" Or s = " Terminé - accepté" Or s = " Terminé sans suite" Or s = " Annulé Gestion" Then
        If s <> "Terminé - Refusé après instruction" Then
            If Month(Cells(i, 2)).Value = 11 And Year(Cells(i, 2)).Value = 2015 Then
                tt = tt + CInt(montant)
            End If
            If Month(Cells(i, 2)).Value = 12 And Year(Cells(i, 2)).Value = 2015 Then
                tt = tt + CInt(montant)
            End If
            If Month(Cells(i, 2)).Value = 1 And Year(Cells(i, 2)).Value = 2016 Then
                tt = tt + CInt(montant)
            End If
            If Month(Cells(i, 2)).Value = 2 And Year(Cells(i, 2)).Value = 2016 Then
                tt = tt + CInt(montant)
            End If
       End If
    Next i

End SubSub MONTANT_INDEMNITE_PRINCIPALE()

    Dim Date_Souscription_Adhésion As Range, Statut_Technique_Sinistre As Range
    Dim Montant_Ind_Principale As Range
    Dim dernligne As Long
    Dim i As Integer
    Dim s As String
    Dim montant As String
    Dim tt As Double

    With Worksheets("Feuil1")
        dernligne = ThisWorkbook.Sheets("Feuil1").Range("A" & .Rows.Count).End(xlUp).Row
        Set Date_Souscription_Adhésion = ThisWorkbook.Sheets("Feuil1").Range("B2:B" & dernligne)
        Set Montant_Ind_Principale = ThisWorkbook.Sheets("Feuil1").Range("E2:E" & dernligne)
        Set Statut_Technique_Sinistre = ThisWorkbook.Sheets("Feuil1").Range("D2:D" & dernligne)
    End With

    For i = 2 To dernligne
        s = Cells(i, 4).Value
        montant = Cells(i, 5).Value
      ' If s = "En cours" Or s = " En attente de prescription" Or s = " Terminé - accepté" Or s = " Terminé sans suite" Or s = " Annulé Gestion" Then
        If s <> "Terminé - Refusé après instruction" Then
            If Month(Cells(i, 2)).Value = 11 And Year(Cells(i, 2)).Value = 2015 Then
                tt = tt + CInt(montant)
            End If
            If Month(Cells(i, 2)).Value = 12 And Year(Cells(i, 2)).Value = 2015 Then
                tt = tt + CInt(montant)
            End If
            If Month(Cells(i, 2)).Value = 1 And Year(Cells(i, 2)).Value = 2016 Then
                tt = tt + CInt(montant)
            End If
            If Month(Cells(i, 2)).Value = 2 And Year(Cells(i, 2)).Value = 2016 Then
                tt = tt + CInt(montant)
            End If
       End If
    Next i

End Sub

aude21, tu fais rire deux fois la fonction !!!

des erreurs de parenthèse fermantes pour récupérrer le mois ou l'année month(cell().values)

essaye d'avoir un montant différents pour chaque mois genre montantnov = montantnov + cells

sinon tu vas faire comme je t'ai envoyé.

    Sub MONTANT_INDEMNITE_PRINCIPALE()

        Dim Date_Souscription_Adhésion As Range, Statut_Technique_Sinistre As Range
        Dim Montant_Ind_Principale As Range
        Dim dernligne As Long
        Dim i As Integer
        Dim s As String
        Dim montant As String
        Dim tt11 As Double
        Dim tt12 As Double
        Dim tt1 As Double
        Dim tt2 As Double

        With Worksheets("Feuil1")
            dernligne = ThisWorkbook.Sheets("Feuil1").Range("A" & .Rows.Count).End(xlUp).Row
            Set Date_Souscription_Adhésion = ThisWorkbook.Sheets("Feuil1").Range("B2:B" & dernligne)
            Set Montant_Ind_Principale = ThisWorkbook.Sheets("Feuil1").Range("E2:E" & dernligne)
            Set Statut_Technique_Sinistre = ThisWorkbook.Sheets("Feuil1").Range("D2:D" & dernligne)
        End With

        For i = 2 To dernligne
            s = Cells(i, 4).Value
            montant = Cells(i, 5).Value
          ' If s = "En cours" Or s = " En attente de prescription" Or s = " Terminé - accepté" Or s = " Terminé sans suite" Or s = " Annulé Gestion" Then
           If s <> "Terminé - Refusé après instruction" Then
'           MsgBox Year(Cells(i, 2).Value)
                If Month(Cells(i, 2).Value) = 11 And Year(Cells(i, 2).Value) = 2015 Then
                    tt11 = tt11 + CInt(montant)
                End If
                If Month(Cells(i, 2).Value) = 12 And Year(Cells(i, 2).Value) = 2015 Then
                    tt12 = tt12 + CInt(montant)
                End If
                If Month(Cells(i, 2).Value) = 1 And Year(Cells(i, 2).Value) = 2016 Then
                    tt1 = tt1 + CInt(montant)
                End If
                If Month(Cells(i, 2).Value) = 2 And Year(Cells(i, 2).Value) = 2016 Then
                    tt2 = tt2 + CInt(montant)
                End If
           End If
        Next i

       

dsll je viens de voir ton message

sa ne marche pas sa ne m'affiche rien

Sub MONTANT_INDEMNITE_PRINCIPALE()

    Dim Date_Souscription_Adhésion As Range, Statut_Technique_Sinistre As Range
    Dim Montant_Ind_Principale As Range
    Dim dernligne As Long
    Dim i As Integer
    Dim s As String
    Dim montant As String
    Dim tt1, tt2, tt3, tt4, tt5, tt6, tt7, tt8, tt9, tt10 As Double
    Dim tt11, tt12, tt13, tt14, tt15, tt16, tt17, tt18, tt19, tt20 As Double
    Dim tt21, tt22, tt23, tt24 As Double

    With Worksheets("Feuil1")
        dernligne = ThisWorkbook.Sheets("Feuil1").Range("A" & .Rows.Count).End(xlUp).Row
        Set Date_Souscription_Adhésion = ThisWorkbook.Sheets("Feuil1").Range("B2:B" & dernligne)
        Set Montant_Ind_Principale = ThisWorkbook.Sheets("Feuil1").Range("E2:E" & dernligne)
        Set Statut_Technique_Sinistre = ThisWorkbook.Sheets("Feuil1").Range("D2:D" & dernligne)
    End With

    For i = 2 To dernligne
        s = Cells(i, 4).Value
        montant = Cells(i, 5).Value
      ' If s = "En cours" Or s = " En attente de prescription" Or s = " Terminé - accepté" Or s = " Terminé sans suite" Or s = " Annulé Gestion" Then
        If s <> "Terminé - Refusé après instruction" Then

            If Month(Cells(i, 7).Value) = 1 And Year(Cells(i, 7).Value) = 2015 Then
                tt1 = tt1 + CInt(montant)
                Sheets("Feuil2").Cells(i, 2).Value = tt1
            End If
            If Month(Cells(i, 7).Value) = 2 And Year(Cells(i, 7).Value) = 2015 Then
                tt2 = tt2 + CInt(montant)
                Sheets("Feuil2").Cells(i, 3).Value = tt2
            End If
            If Month(Cells(i, 7).Value) = 3 And Year(Cells(i, 7).Value) = 2015 Then
                tt3 = tt3 + CInt(montant)
                Sheets("Feuil2").Cells(i, 4).Value = tt3
            End If
            If Month(Cells(i, 7).Value) = 4 And Year(Cells(i, 7).Value) = 2015 Then
                tt4 = tt4 + CInt(montant)
                Sheets("Feuil2").Cells(i, 5).Value = tt4
            End If
            If Month(Cells(i, 7).Value) = 5 And Year(Cells(i, 7).Value) = 2015 Then
                tt5 = tt5 + CInt(montant)
                Sheets("Feuil2").Cells(i, 6).Value = tt5
            End If
            If Month(Cells(i, 7).Value) = 6 And Year(Cells(i, 7).Value) = 2015 Then
                tt6 = tt6 + CInt(montant)
                Sheets("Feuil2").Cells(i, 7).Value = tt6
            End If
            If Month(Cells(i, 7).Value) = 7 And Year(Cells(i, 7).Value) = 2015 Then
                tt7 = tt7 + CInt(montant)
                Sheets("Feuil2").Cells(i, 8).Value = tt7
            End If
            If Month(Cells(i, 7).Value) = 8 And Year(Cells(i, 7).Value) = 2015 Then
                tt8 = tt8 + CInt(montant)
                Sheets("Feuil2").Cells(i, 9).Value = tt8
            End If
            If Month(Cells(i, 7).Value) = 9 And Year(Cells(i, 7).Value) = 2015 Then
                tt9 = tt9 + CInt(montant)
                Sheets("Feuil2").Cells(i, 10).Value = tt9
            End If
            If Month(Cells(i, 7).Value) = 10 And Year(Cells(i, 7).Value) = 2015 Then
                tt10 = tt10 + CInt(montant)
                Sheets("Feuil2").Cells(i, 11).Value = tt10
            End If
            If Month(Cells(i, 7).Value) = 11 And Year(Cells(i, 7).Value) = 2015 Then
                tt11 = tt11 + CInt(montant)
                Sheets("Feuil2").Cells(i, 12).Value = tt11
            End If
            If Month(Cells(i, 7).Value) = 12 And Year(Cells(i, 7).Value) = 2015 Then
                tt12 = tt12 + CInt(montant)
                Sheets("Feuil2").Cells(i, 13).Value = tt12
            End If
            If Month(Cells(i, 7).Value) = 1 And Year(Cells(i, 7).Value) = 2016 Then
                tt13 = tt13 + CInt(montant)
                Sheets("Feuil2").Cells(i, 14).Value = tt3
            End If
            If Month(Cells(i, 7).Value) = 2 And Year(Cells(i, 7).Value) = 2016 Then
                tt14 = tt14 + CInt(montant)
                Sheets("Feuil2").Cells(i, 15).Value = tt14
            End If
            If Month(Cells(i, 7).Value) = 3 And Year(Cells(i, 7).Value) = 2016 Then
                tt15 = tt15 + CInt(montant)
                Sheets("Feuil2").Cells(i, 16).Value = tt15
            End If
            If Month(Cells(i, 7).Value) = 4 And Year(Cells(i, 7).Value) = 2016 Then
                tt16 = tt16 + CInt(montant)
                Sheets("Feuil2").Cells(i, 17).Value = tt16
            End If
            If Month(Cells(i, 7).Value) = 5 And Year(Cells(i, 7).Value) = 2016 Then
                tt17 = tt17 + CInt(montant)
                Sheets("Feuil2").Cells(i, 18).Value = tt17
            End If
            If Month(Cells(i, 7).Value) = 6 And Year(Cells(i, 7).Value) = 2016 Then
                tt18 = tt18 + CInt(montant)
                Sheets("Feuil2").Cells(i, 19).Value = tt18
            End If
            If Month(Cells(i, 7).Value) = 7 And Year(Cells(i, 7).Value) = 2016 Then
                tt19 = tt19 + CInt(montant)
                Sheets("Feuil2").Cells(i, 20).Value = tt19
            End If
            If Month(Cells(i, 7).Value) = 8 And Year(Cells(i, 7).Value) = 2016 Then
                tt20 = tt20 + CInt(montant)
                Sheets("Feuil2").Cells(i, 21).Value = tt20
            End If
            If Month(Cells(i, 7).Value) = 9 And Year(Cells(i, 7).Value) = 2016 Then
                tt21 = tt21 + CInt(montant)
                Sheets("Feuil2").Cells(i, 22).Value = tt21
            End If
            If Month(Cells(i, 7).Value) = 10 And Year(Cells(i, 7).Value) = 2016 Then
                tt22 = tt22 + CInt(montant)
                Sheets("Feuil2").Cells(i, 23).Value = tt22
            End If
            If Month(Cells(i, 7).Value) = 11 And Year(Cells(i, 7).Value) = 2016 Then
                tt23 = tt23 + CInt(montant)
                Sheets("Feuil2").Cells(i, 24).Value = tt23
            End If
            If Month(Cells(i, 7).Value) = 12 And Year(Cells(i, 7).Value) = 2016 Then
                tt24 = tt24 + CInt(montant)
                Sheets("Feuil2").Cells(i, 25).Value = tt24
            End If
       End If
    Next i

End Sub
2exple-4v1-3.xlsm (49.62 Ko)
Rechercher des sujets similaires à "probleme code"