Nombre de vendredi 13 de ma naissance jusqu'à aujourdhui
34 réponses
Tatanka
Bonsoir,
J'ai adapté une macro trouvée ici :
http://www.docmemo.com/divers/vendredi13.php
me permettant d'obtenir la liste de tous les « vendredi 13 »
de 1945 jusqu'à 2011. Le résultat me satisfait mais par
souci d'apprentissage, comment la modifier pour que cette
liste ne couvre que la période du 10 mai 1945 jusqu'à
la date du jour ? Voici la macro :
Sub Vendredi_13()
Dim Année, Mois, Compteur, NomMois(12)
NomMois(1) = "janvier"
NomMois(2) = "février"
NomMois(3) = "mars"
NomMois(4) = "avril"
NomMois(5) = "mai"
NomMois(6) = "juin"
NomMois(7) = "juillet"
NomMois(8) = "août"
NomMois(9) = "septembre"
NomMois(10) = "octobre"
NomMois(11) = "novembre"
NomMois(12) = "décembre"
For Année = 1945 To 2011
For Mois = 1 To 12
If Weekday(Mois & "/13/" & Année) = 6 Then
Range("A1").Offset(Compteur, 0) = "13 " _
& NomMois(Mois) & " " & Année
Compteur = Compteur + 1
End If
Next Mois
Next Année
End Sub
Mais y a- t-il vraiment dans ce cas, un gain de temps d'exécution signifiant Ma macro est moins rapide je l'admets, mais moins de 1 seconde dans les 2 procédures
31 ms !!! Dies ist wo man werden sehen, dass ich Recht in investieren mich in EXCEL das ist nich Nicholas !!!
Declare Function GetTickCount& Lib "kernel32" ()
Sub vendredi13() debut = 1945 x = 1: y = 1 d = GetTickCount While newdate < Date newdate = DateSerial(debut, x, 13) If Weekday(newdate) = 6 Then Cells(y, 1) = newdate : y = y + 1 x = x + 1 Wend MsgBox (GetTickCount - d) / 1000 & " sec"
Bonsour®
Dupond@marcel.fr a
Mais y a- t-il vraiment dans ce cas, un gain de temps d'exécution signifiant
Ma macro est moins rapide je l'admets, mais moins de 1 seconde dans les 2
procédures
31 ms !!!
Dies ist wo man werden sehen, dass ich Recht in investieren mich in EXCEL
das ist nich Nicholas !!!
Declare Function GetTickCount& Lib "kernel32" ()
Sub vendredi13()
debut = 1945
x = 1: y = 1
d = GetTickCount
While newdate < Date
newdate = DateSerial(debut, x, 13)
If Weekday(newdate) = 6 Then Cells(y, 1) = newdate : y = y + 1
x = x + 1
Wend
MsgBox (GetTickCount - d) / 1000 & " sec"
Mais y a- t-il vraiment dans ce cas, un gain de temps d'exécution signifiant Ma macro est moins rapide je l'admets, mais moins de 1 seconde dans les 2 procédures
31 ms !!! Dies ist wo man werden sehen, dass ich Recht in investieren mich in EXCEL das ist nich Nicholas !!!
Declare Function GetTickCount& Lib "kernel32" ()
Sub vendredi13() debut = 1945 x = 1: y = 1 d = GetTickCount While newdate < Date newdate = DateSerial(debut, x, 13) If Weekday(newdate) = 6 Then Cells(y, 1) = newdate : y = y + 1 x = x + 1 Wend MsgBox (GetTickCount - d) / 1000 & " sec"
Tatanka
La plus élégante : Celle de Modeste. La plus rapide ( mais qu'est-ce qu'on s'en fout :-) ) :
Sub Vendredi_13_Daniel_3() t = Timer Application.ScreenUpdating = False Dim NomMois(12) Dim d As Date, Année As Integer, Compteur As Integer Dim i As Byte, début As Date, Mois As Byte For i = 1 To 12 NomMois(i) = i Next i début = #5/10/1945# For Année = 1945 To 2011 For Mois = 1 To 12 d = DateSerial(Année, Mois, 13) If d > Date Then Exit For 'Mini modif If Weekday(d) = 6 And d >= début Then Range("A1").Offset(Compteur, 0) = _ Format(d, "dd mmmm yyyy") Compteur = Compteur + 1 End If Next Mois Next Année MsgBox Timer - t Application.ScreenUpdating = True
Serge
La plus élégante : Celle de Modeste.
La plus rapide ( mais qu'est-ce qu'on s'en fout :-) ) :
Sub Vendredi_13_Daniel_3()
t = Timer
Application.ScreenUpdating = False
Dim NomMois(12)
Dim d As Date, Année As Integer, Compteur As Integer
Dim i As Byte, début As Date, Mois As Byte
For i = 1 To 12
NomMois(i) = i
Next i
début = #5/10/1945#
For Année = 1945 To 2011
For Mois = 1 To 12
d = DateSerial(Année, Mois, 13)
If d > Date Then Exit For 'Mini modif
If Weekday(d) = 6 And d >= début Then
Range("A1").Offset(Compteur, 0) = _
Format(d, "dd mmmm yyyy")
Compteur = Compteur + 1
End If
Next Mois
Next Année
MsgBox Timer - t
Application.ScreenUpdating = True
La plus élégante : Celle de Modeste. La plus rapide ( mais qu'est-ce qu'on s'en fout :-) ) :
Sub Vendredi_13_Daniel_3() t = Timer Application.ScreenUpdating = False Dim NomMois(12) Dim d As Date, Année As Integer, Compteur As Integer Dim i As Byte, début As Date, Mois As Byte For i = 1 To 12 NomMois(i) = i Next i début = #5/10/1945# For Année = 1945 To 2011 For Mois = 1 To 12 d = DateSerial(Année, Mois, 13) If d > Date Then Exit For 'Mini modif If Weekday(d) = 6 And d >= début Then Range("A1").Offset(Compteur, 0) = _ Format(d, "dd mmmm yyyy") Compteur = Compteur + 1 End If Next Mois Next Année MsgBox Timer - t Application.ScreenUpdating = True
Serge
DanielCo
Bien compris, mais quelle que soit la macro, le but est de faire rapide, même si dans le cas précis, c'est insignifiant. Daniel
Bien compris, mais quelle que soit la macro, le but est de faire
rapide, même si dans le cas précis, c'est insignifiant.
Daniel
La plus rapide ( mais qu'est-ce qu'on s'en fout :-) ) :
... de calculer un nombre de vendredi 13 aussi, note bien. ;-))) Daniel
Tatanka
Et voilà tout à coup que cette macro bloque à Compteur = Compteur + 1. Si je l'exécute pas à pas, le Compteur reste toujours à 0 ! Où est le problème ?
Sub Vendredi_13_Daniel_3() t = Timer Application.ScreenUpdating = False Dim NomMois(12) Dim d As Date, Année As Integer, Compteur As Integer Dim i As Byte, début As Date, Mois As Byte For i = 1 To 12 NomMois(i) = i Next i début = #5/10/1945# For Année = 1945 To 2011 For Mois = 1 To 12 d = DateSerial(Année, Mois, 13) If d > Date Then Exit For 'Mini modif If Weekday(d) = 6 And d >= début Then Range("A1").Offset(Compteur, 0) = Format(d, "dd mmmm yyyy") Compteur = Compteur + 1 End If Next Mois Next Année MsgBox Timer - t Application.ScreenUpdating = True End Sub
Et voilà tout à coup que cette macro bloque à
Compteur = Compteur + 1.
Si je l'exécute pas à pas, le Compteur reste toujours à 0 !
Où est le problème ?
Sub Vendredi_13_Daniel_3()
t = Timer
Application.ScreenUpdating = False
Dim NomMois(12)
Dim d As Date, Année As Integer, Compteur As Integer
Dim i As Byte, début As Date, Mois As Byte
For i = 1 To 12
NomMois(i) = i
Next i
début = #5/10/1945#
For Année = 1945 To 2011
For Mois = 1 To 12
d = DateSerial(Année, Mois, 13)
If d > Date Then Exit For 'Mini modif
If Weekday(d) = 6 And d >= début Then
Range("A1").Offset(Compteur, 0) = Format(d, "dd mmmm yyyy")
Compteur = Compteur + 1
End If
Next Mois
Next Année
MsgBox Timer - t
Application.ScreenUpdating = True
End Sub
Et voilà tout à coup que cette macro bloque à Compteur = Compteur + 1. Si je l'exécute pas à pas, le Compteur reste toujours à 0 ! Où est le problème ?
Sub Vendredi_13_Daniel_3() t = Timer Application.ScreenUpdating = False Dim NomMois(12) Dim d As Date, Année As Integer, Compteur As Integer Dim i As Byte, début As Date, Mois As Byte For i = 1 To 12 NomMois(i) = i Next i début = #5/10/1945# For Année = 1945 To 2011 For Mois = 1 To 12 d = DateSerial(Année, Mois, 13) If d > Date Then Exit For 'Mini modif If Weekday(d) = 6 And d >= début Then Range("A1").Offset(Compteur, 0) = Format(d, "dd mmmm yyyy") Compteur = Compteur + 1 End If Next Mois Next Année MsgBox Timer - t Application.ScreenUpdating = True End Sub
Jacky
La plus rapide ( mais qu'est-ce qu'on s'en fout :-) ) :
Bonjour, objection : il me semble que celle de Daniel , à compter du jeudi 12 mai 2011 au soir ne sera plus valable alors que Rolande me porte bonheur ! ;-) Amicalement
Michel
Bonjour,
objection : il me semble que celle de Daniel , à compter du jeudi 12 mai
2011 au soir ne sera plus valable
alors que Rolande me porte bonheur !
;-)
Amicalement
Bonjour, objection : il me semble que celle de Daniel , à compter du jeudi 12 mai 2011 au soir ne sera plus valable alors que Rolande me porte bonheur ! ;-) Amicalement
Michel
Tatanka
Encore pire !!! Toutes les macros proposées renvoient « Exécution interrompue » quand je les appelle pourtant poliment ! C'est quoi ça ? ;-)
Serge
Encore pire !!!
Toutes les macros proposées renvoient « Exécution interrompue »
quand je les appelle pourtant poliment !
C'est quoi ça ? ;-)