Calcul du nombre de ligne
a
Bonjour
je ne comprend pas pourquoi il ne veut pas me calculer le nombre de ligne
merci de vos reponse
Sub test()
Dim Date_Souscription_Adhésion As Range 'définit les variables
Dim Date_Survenance As Range
Dim i As Integer
Dim j As Integer
Dim DernLigne1 As Long
Dim DernLigne2 As Long
Worksheets("Feuil1").Activate
DernLigne1 = Sheets("Feuil1").Range("A" & Rows.Count).End(xlUp).Row 'définit la dernière ligne colonne A
DernLigne2 = Sheets("Feuil1").Range("B" & Rows.Count).End(xlUp).Row 'définit la dernière ligne colonne B
Set Date_Souscription_Adhésion = Sheets("Feuil1").Range("A2:A" & DernLigne1) 'définit la colonne A
Set Date_Survenance = Sheets("Feuil1").Range("B2:B" & DernLigne2) 'définit la colonne B
For i = 1 To Date_Souscription_Adhésion.Rows.Count ' boucle sur la colonne A
For j = 1 To Date_Survenance.Rows.Count ' boucle sur la colonne B
If Year(Date_Souscription_Adhésion(i, 1)) = 2013 Then 'i étant la ligne de 2 à dernière ligne et 1 la colonne A
If Month(Date_Souscription_Adhésion(i, 1)) = 1 Then
If Year(Date_Survenance(j, 1)) = 2013 Then 'j étant la ligne de 2 à dernière ligne et 1 la colonne B
If Month(Date_Survenance(j, 1)) = 1 Then
nblignes = Range("A2", Range("A7").End(xlUp)).Rows.Count 'compter le nombre de ligne
End If
End If
End If
End If
MsgBox "le nombre de sinistre declarer en janvier est" & nblignes
Next j
Next i
End Sub
A tester ...
Sub test()
Dim Date_Souscription_Adhésion As Range 'définit les variables
Dim Date_Survenance As Range
Dim i As Integer
Dim j As Integer
Dim DernLigne1 As Long
Dim DernLigne2 As Long
Worksheets("Feuil1").Activate
DernLigne1 = Sheets("Feuil1").Range("A" & Rows.Count).End(xlUp).Row 'définit la dernière ligne colonne A
DernLigne2 = Sheets("Feuil1").Range("B" & Rows.Count).End(xlUp).Row 'définit la dernière ligne colonne B
Set Date_Souscription_Adhésion = Sheets("Feuil1").Range("A2:A" & DernLigne1) 'définit la colonne A
Set Date_Survenance = Sheets("Feuil1").Range("B2:B" & DernLigne2) 'définit la colonne B
nblignes = 0
For i = 1 To Date_Souscription_Adhésion.Rows.Count ' boucle sur la colonne A
For j = 1 To Date_Survenance.Rows.Count ' boucle sur la colonne B
If Year(Date_Souscription_Adhésion(i, 1)) = 2013 Then 'i étant la ligne de 2 à dernière ligne et 1 la colonne A
If Month(Date_Souscription_Adhésion(i, 1)) = 1 Then
If Year(Date_Survenance(j, 1)) = 2013 Then 'j étant la ligne de 2 à dernière ligne et 1 la colonne B
If Month(Date_Survenance(j, 1)) = 1 Then
nblignes = nblignes + 1 'compter le nombre de ligne
End If
End If
End If
End If
Next j
Next i
MsgBox "le nombre de sinistre declarer en janvier est " & nblignes
End Suba
super merci beaucoup sa marche
sa ne marche pas il me donne pas les bonnes valeurs
jai tester sur le fichier excel ci joint
Sub test()
Dim Date_Souscription_Adhésion As Range 'définit les variables
Dim Date_Survenance As Range
Dim i As Integer
Dim j As Integer
Dim DernLigne1 As Long
Dim DernLigne2 As Long
Worksheets("Feuil1").Activate
DernLigne1 = Sheets("Feuil1").Range("A" & Rows.Count).End(xlUp).Row 'définit la dernière ligne colonne A
DernLigne2 = Sheets("Feuil1").Range("B" & Rows.Count).End(xlUp).Row 'définit la dernière ligne colonne B
Set Date_Souscription_Adhésion = Sheets("Feuil1").Range("A2:A" & DernLigne1) 'définit la colonne A
Set Date_Survenance = Sheets("Feuil1").Range("B2:B" & DernLigne2) 'définit la colonne B
nblignes = 0
nblignes2 = 0
For i = 1 To Date_Souscription_Adhésion.Rows.Count ' boucle sur la colonne A
For j = 1 To Date_Survenance.Rows.Count ' boucle sur la colonne B
If Year(Date_Souscription_Adhésion(i, 1)) = 2013 Then 'i étant la ligne de 2 à dernière ligne et 1 la colonne A
If Month(Date_Souscription_Adhésion(i, 1)) = 1 Then
If Year(Date_Survenance(j, 1)) = 2013 Then 'j étant la ligne de 2 à dernière ligne et 1 la colonne B
If Month(Date_Survenance(j, 1)) = 1 Then
nblignes = nblignes + 1 'Range("A2", Range("A7").End(xlUp)).Rows.Count 'compter le nombre de ligne
End If
End If
End If
If Month(Date_Souscription_Adhésion(i, 1)) = 1 Then
If Year(Date_Survenance(j, 1)) = 2013 Then 'j étant la ligne de 2 à dernière ligne et 1 la colonne B
If Month(Date_Survenance(j, 1)) = 2 Then
nblignes2 = nblignes2 + 1 'Range("A2", Range("A7").End(xlUp)).Rows.Count 'compter le nombre de ligne
End If
End If
End If
End If
Next j
Next i
MsgBox "le nombre de sinistre declarer en janvier est" & nblignes
MsgBox "le nombre de sinistre declarer en fevrier est" & nblignes2
End Sub