j'ai des dates qui se situent de F2 à IV2 et je voudrais rechercher toutes les dates qui correspondent au samedi
j'ai essayé quelque chose comme ça
Code:
For Each cel In Range("F2:IV2")
datejour = cel.Value
If datejour.Day = sam Then
col = ActiveCell.Column
Range(Cells(ligne, col), Cells(ligne + 13, col + 1)).Select
Selection.Interior.ColorIndex = 39
End If
Next cel
Sub test()
Dim cel As Range
For Each cel In Range("F2:IV2")
If IsDate(cel.Value) Then _
If Weekday(cel.Value, 2) = 6 Then cel.Interior.ColorIndex = 39
Next cel
End Sub
bon après midi
@+
Aarf Gael, bonjour, pas raffraichi...trop rapide pour moi.
Gael a raison ! le VBmonday indique que la semaine commence le Lundi. Samedi est donc le 6e jour de la semaine. Contrairement au US ou le premier jour de la semaine est le dimanche.
Code:
Sub samedi()
Dim datejour As Date
Dim cel As Range
For Each cel In Range("F2:IV2")
datejour = cel.Value
If Weekday(datejour, vbMonday) = 6 Then
cel.Interior.ColorIndex = 39
End If
Next cel
End Sub
For Each cel In Range("F2:IV2")
cel.Select
If Weekday(cel.Value, vbMonday) = 6 Then
col = ActiveCell.Column
Range(Cells(ligne, col), Cells(ligne + 13, col + 1)).Select
Selection.Interior.ColorIndex = 39
End If
Next
[LEFT]For Each cel In Range("F2:IV2")
If Weekday(cel.Value, vbMonday) = 6 Then
col = Cel.Column
Range(Cells(ligne, col), Cells(ligne + 13, col +1)).Interior.ColorIndex = 39
End If[/LEFT]
[LEFT] Next[/LEFT]