aude2111
Habitué
Bonjour
je suis débutante en vba, j'ai un petit problème
j'ai envie de calculer le nombre de sinistre par mois, pour cela j'ai fais le code ci dessus
cependant je ne veux pas qu'il me renvoie de MsgBox mais quil mecrivent la reponse directement sur la feuil 2 (en A2 la premiere ligne je la laisse au titre) pour que moi depuis la feuille 2 je fais un copier coller que je colle sur un autre fichier
je suis débutante en vba, j'ai un petit problème
j'ai envie de calculer le nombre de sinistre par mois, pour cela j'ai fais le code ci dessus
cependant je ne veux pas qu'il me renvoie de MsgBox mais quil mecrivent la reponse directement sur la feuil 2 (en A2 la premiere ligne je la laisse au titre) pour que moi depuis la feuille 2 je fais un copier coller que je colle sur un autre fichier
Sub test()
Dim Date_Souscription_Adhésion As Range, Date_Survenance As Range
Dim DernLigne As Long
Dim nblignes, nblignes1, nblignes2, nblignes3, nblignes4 As Long
Dim nblignes5, nblignes6, nblignes7, nblignes8, nblignes9 As Long
Dim nblignes10, nblignes11 As Long
With Worksheets("Feuil1")
DernLigne = .Range("A" & .Rows.Count).End(xlUp).Row
Set Date_Souscription_Adhésion = .Range("G2:G" & DernLigne)
Set Date_Survenance = .Range("R2:R" & DernLigne)
End With
nblignes = 0
nblignes1 = 0
nblignes2 = 0
nblignes3 = 0
nblignes4 = 0
nblignes5 = 0
nblignes6 = 0
nblignes7 = 0
nblignes8 = 0
nblignes9 = 0
nblignes10 = 0
nblignes11 = 0
a = 2013
b = 2014
c = 2015
d = 2016
e = 2017
jan = 1
fev = 2
mars = 3
avril = 4
mai = 5
juin = 6
juil = 7
aout = 8
sep = 9
oc = 10
nov = 11
dec = 12
For i = 2 To DernLigne
If DateSerial(c, jan, 1) <= Cells(i, 7).Value And Cells(i, 7).Value <= DateSerial(c, jan, 31) And DateSerial(a, jan, 1) <= Cells(i, 18).Value And Cells(i, 18).Value <= DateSerial(e, dec, 31) Then
nblignes = nblignes + 1
'Cells(i, 6).Value = 1 'incremente pour voir quel resultat il prend
'Cells(i, 1).Select
End If
Next i
MsgBox "nombre de lignes : " & nblignes
For i = 2 To DernLigne
If DateSerial(c, fev, 1) <= Cells(i, 7).Value And Cells(i, 7).Value <= DateSerial(c, fev, 31) And DateSerial(a, jan, 1) <= Cells(i, 18).Value And Cells(i, 18).Value <= DateSerial(e, dec, 31) Then
nblignes1 = nblignes1 + 1
'Cells(i, 6).Value = 1 'incremente pour voir quel resultat il prend
'Cells(i, 1).Select
End If
Next i
MsgBox "nombre de lignes : " & nblignes1
For i = 2 To DernLigne
If DateSerial(c, mars, 1) <= Cells(i, 7).Value And Cells(i, 7).Value <= DateSerial(c, mars, 31) And DateSerial(a, jan, 1) <= Cells(i, 18).Value And Cells(i, 18).Value <= DateSerial(e, dec, 31) Then
nblignes2 = nblignes2 + 1
'Cells(i, 6).Value = 1 'incremente pour voir quel resultat il prend
'Cells(i, 1).Select
End If
Next i
MsgBox "nombre de lignes : " & nblignes2
For i = 2 To DernLigne
If DateSerial(c, avril, 1) <= Cells(i, 7).Value And Cells(i, 7).Value <= DateSerial(c, avril, 31) And DateSerial(a, jan, 1) <= Cells(i, 18).Value And Cells(i, 18).Value <= DateSerial(e, dec, 31) Then
nblignes3 = nblignes3 + 1
'Cells(i, 6).Value = 1 'incremente pour voir quel resultat il prend
'Cells(i, 1).Select
End If
Next i
MsgBox "nombre de lignes : " & nblignes3
For i = 2 To DernLigne
If DateSerial(c, mai, 1) <= Cells(i, 7).Value And Cells(i, 7).Value <= DateSerial(c, mai, 31) And DateSerial(a, jan, 1) <= Cells(i, 18).Value And Cells(i, 18).Value <= DateSerial(e, dec, 31) Then
nblignes4 = nblignes4 + 1
'Cells(i, 6).Value = 1 'incremente pour voir quel resultat il prend
'Cells(i, 1).Select
End If
Next i
MsgBox "nombre de lignes : " & nblignes4
For i = 2 To DernLigne
If DateSerial(c, juin, 1) <= Cells(i, 7).Value And Cells(i, 7).Value <= DateSerial(c, juin, 31) And DateSerial(a, jan, 1) <= Cells(i, 18).Value And Cells(i, 18).Value <= DateSerial(e, dec, 31) Then
nblignes5 = nblignes5 + 1
'Cells(i, 6).Value = 1 'incremente pour voir quel resultat il prend
'Cells(i, 1).Select
End If
Next i
MsgBox "nombre de lignes : " & nblignes5
For i = 2 To DernLigne
If DateSerial(c, juil, 1) <= Cells(i, 7).Value And Cells(i, 7).Value <= DateSerial(c, juil, 31) And DateSerial(a, jan, 1) <= Cells(i, 18).Value And Cells(i, 18).Value <= DateSerial(e, dec, 31) Then
nblignes6 = nblignes6 + 1
'Cells(i, 6).Value = 1 'incremente pour voir quel resultat il prend
'Cells(i, 1).Select
End If
Next i
MsgBox "nombre de lignes : " & nblignes6
For i = 2 To DernLigne
If DateSerial(c, aout, 1) <= Cells(i, 7).Value And Cells(i, 7).Value <= DateSerial(c, aout, 31) And DateSerial(a, jan, 1) <= Cells(i, 18).Value And Cells(i, 18).Value <= DateSerial(e, dec, 31) Then
nblignes7 = nblignes7 + 1
'Cells(i, 6).Value = 1 'incremente pour voir quel resultat il prend
'Cells(i, 1).Select
End If
Next i
MsgBox "nombre de lignes : " & nblignes7
For i = 2 To DernLigne
If DateSerial(c, sep, 1) <= Cells(i, 7).Value And Cells(i, 7).Value <= DateSerial(c, sep, 31) And DateSerial(a, jan, 1) <= Cells(i, 18).Value And Cells(i, 18).Value <= DateSerial(e, dec, 31) Then
nblignes8 = nblignes8 + 1
'Cells(i, 6).Value = 1 'incremente pour voir quel resultat il prend
'Cells(i, 1).Select
End If
Next i
MsgBox "nombre de lignes : " & nblignes8
For i = 2 To DernLigne
If DateSerial(c, oc, 1) <= Cells(i, 7).Value And Cells(i, 7).Value <= DateSerial(c, oc, 31) And DateSerial(a, jan, 1) <= Cells(i, 18).Value And Cells(i, 18).Value <= DateSerial(e, dec, 31) Then
nblignes9 = nblignes9 + 1
'Cells(i, 6).Value = 1 'incremente pour voir quel resultat il prend
'Cells(i, 1).Select
End If
Next i
MsgBox "nombre de lignes : " & nblignes9
For i = 2 To DernLigne
If DateSerial(c, nov, 1) <= Cells(i, 7).Value And Cells(i, 7).Value <= DateSerial(c, nov, 31) And DateSerial(a, jan, 1) <= Cells(i, 18).Value And Cells(i, 18).Value <= DateSerial(e, dec, 31) Then
nblignes10 = nblignes10 + 1
'Cells(i, 6).Value = 1 'incremente pour voir quel resultat il prend
'Cells(i, 1).Select
End If
Next i
MsgBox "nombre de lignes : " & nblignes10
For i = 2 To DernLigne
If DateSerial(c, dec, 1) <= Cells(i, 7).Value And Cells(i, 7).Value <= DateSerial(c, dec, 31) And DateSerial(a, jan, 1) <= Cells(i, 18).Value And Cells(i, 18).Value <= DateSerial(e, dec, 31) Then
nblignes11 = nblignes11 + 1
'Cells(i, 6).Value = 1 'incremente pour voir quel resultat il prend
'Cells(i, 1).Select
End If
Next i
MsgBox "nombre de lignes : " & nblignes11
'Selection.Copy
'Worksheets("Feuil2").Activate
'Destination = Sheets("Feuil2").Range("B1")
End Sub