SORRY I POSTED THIS BUT AFTER FURTHER TESTING THIS IS NOT WORKING AS SUPPOSED AS I HAD THE RED LINE IT WAS MOVING FINE WHEN SORTING BUT IF NO LINE DOESN'T GENERATE THE LINES....
Don't have time to look at it anyfurther today, will check back on it tomorrow.
Sorry once again
========================================
Hie again,
I have been as always too fast to answer.
Yes this can be put on the change event
If your column F of dates are sorted this should work [meaning the first one will have the red on top]
Think a minute about it: If you have several cell with let's say with Monday 24 October 2006
How are you going to tell wich is the first one if they are identical.
The point is trying to put the line of the first one will work when you sort but depending on which field you sort by the red line will not be on the correct date
The question about not using a Monday as the first day of the week do you mean your week starts on another day or your weekly data may be starting on a different day every week.
Here modified code that involves the first Monday for each week with red line from A to AL
If your week is not starting on a Monday changing line [changing the 1 to 2 if Tuesday,3 if Wednesday should do the trick.
If Weekday(rowi, vbMonday) = 1
Code:
Sub PutARedLineAboveMonday()
'replace sheet1 by the codename of your sheet
Dim rowi As Range
For Each rowi In Sheet1.Columns(6).Cells
If VarType(rowi) = vbDate Then
If Weekday(rowi, vbMonday) = 1 And WorksheetFunction.CountIf(Range("f1:f" & rowi.Row - 1), rowi) = 0 Then
entirerowredtop Range("a" & rowi.Row & ":AL" & rowi.Row), 3, True
Else
entirerowredtop Range("a" & rowi.Row & ":AL" & rowi.Row), 1, False
End If
End If
Next
End Sub
Sub entirerowredtop(rowi As Range, colorchosen As Integer, thickline As Boolean)
With rowi
.Borders(xlEdgeTop).LineStyle = xlContinuous
If thickline = True Then
.Borders(xlEdgeTop).Weight = xlThick
Else
.Borders(xlEdgeTop).Weight = xlThin
End If
.Borders(xlEdgeTop).ColorIndex = colorchosen
End With
End Sub
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Me.PutARedLineAboveMonday
End Sub
See how it works this time, not yet perfect but improving