Bonjour,
Jai une erreur fin instruction sur pc 2007 sur lequel le fichier doit fonctionner, j'ai teste sur excel plus récent cela fonctionne parfaitement.
Le code erreur est en bleu
Merci.
Private Sub balayageFeuille(ByVal nomFeuille As String)
Dim numLigne As Integer
Dim jourAnniv1 As Date, jourAnniv2 As Date
Dim nbLignes As Long: nbLignes = Sheets(nomFeuille).Cells(Rows.Count, "A").End(xlUp).row
Dim temp As Integer
If nbLignes < 3 Then Exit Sub
For numLigne = 3 To nbLignes
'2 cas:
'Soit on va passer à l'année prochaine -> il faut tester les annivs avec année + 1
'Soit on est en milieu d'année
jourAnniv1 = DateSerial(Year(Now), Month(Sheets(nomFeuille).Cells(numLigne, 3)), Day(Sheets(nomFeuille).Cells(numLigne, 3)))
jourAnniv2 = DateSerial(Year(Now) + 1, Month(Sheets(nomFeuille).Cells(numLigne, 3)), Day(Sheets(nomFeuille).Cells(numLigne, 3)))
If DateDiff("y", Now, jourAnniv1) < 0 Then 'Anniv passé cette année
temp = DateDiff("y", Now, jourAnniv2)
Else
temp = DateDiff("y", Now, jourAnniv1)
End If
If temp = 0 Then 'c'est son anniv
With listAnnivToday
.AddItem
.List(.ListCount - 1, 0) = nomFeuille
.List(.ListCount - 1, 1) = Sheets(nomFeuille).Cells(numLigne, 1)
.List(.ListCount - 1, 2) = Sheets(nomFeuille).Cells(numLigne, 2)
.List(.ListCount - 1, 3) = Sheets(nomFeuille).Cells(numLigne, 9)
End With
ElseIf temp > 0 And temp <= 7 Then 'c'est bientot son anniv
With listAnniv7J
.AddItem
.List(.ListCount - 1, 0) = nomFeuille
.List(.ListCount - 1, 1) = Sheets(nomFeuille).Cells(numLigne, 1)
.List(.ListCount - 1, 2) = Sheets(nomFeuille).Cells(numLigne, 2)
.List(.ListCount - 1, 3) = Sheets(nomFeuille).Cells(numLigne, 3)
.List(.ListCount - 1, 4) = Sheets(nomFeuille).Cells(numLigne, 9)
End With
End If
Next numLigne
End Sub