1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
Private Sub Workbook_Open()
Dim Plage As Range
Dim Cel As Range
Dim Tbl() As String
Dim Mois As String
Dim I As Integer
Dim Chaine As String
'extrait le nom du mois de la date
Mois = UCase(MonthName(Month(Date), False))
'défini la plage de recherche sur la ligne 2 à partir de la colonne B
With Worksheets("Feuil1"): Set Plage = .Range(.Cells(2, 2), .Cells(2, .Columns.Count).End(xlToLeft)): End With
'recherche la cellule correspondante
Set Cel = Plage.Find(Mois, , xlValues, xlWhole)
'redéfini la plage sur la bonne colonne
With Worksheets("Feuil1"): Set Plage = .Range(.Cells(3, Cel.Column + 1), .Cells(33, Cel.Column + 1)): End With
For Each Cel In Plage
If Cel.Value <> "" Then
I = I + 1: ReDim Preserve Tbl(1 To 2, 1 To I)
Tbl(1, I) = Cel.Value 'nom de la personne
Tbl(2, I) = Cel.Offset(, -1).Value 'le jour
End If
Next Cel
'si initialisé, au moins un nom trouvé donc, affichage
If Not Not Tbl() Then
For I = 1 To UBound(Tbl, 2): Chaine = Chaine & Tbl(1, I) & " le " & Tbl(2, I) & vbCrLf: Next I
MsgBox "Ce mois -ci (" & Mois & "), c'est l'anniversaire de :" & vbCrLf & Chaine
End If
End Sub |
Partager