Private Sub Worksheet_Change(ByVal Target As Range)
If Not (Intersect(Target, Range("D2:BC2")) Is Nothing) Then
inarr = Range("D2:bc2")
std = Cells(2, 1)
etd = Cells(2, 2)
syr = Year(std)
started = False
ended = False
For i = 1 To 52
If (inarr(1, i)) <> "" And Not (started) Then
std = DateAdd("ww", i - 1, DateSerial(syr, 1, 1))
started = True
End If
If (inarr(1, i)) = "" And (started) And Not (ended) Then
etd = DateAdd("ww", i - 1, DateSerial(syr, 1, 1))
ended = True
End If
Next i
Application.EnableEvents = False
Cells(2, 1) = std
Cells(2, 2) = etd
Application.EnableEvents = True
End If
If Not (Intersect(Target, Range("A2:B2")) Is Nothing) Then
std = Cells(2, 1)
swkno = Application.WorksheetFunction.WeekNum(std)
etd = Cells(2, 2)
ewkno = Application.WorksheetFunction.WeekNum(etd)
dater = Range(Cells(2, 4), Cells(2, 56))
For i = 1 To 52
If i < swkno Then
dater(1, i) = ""
Else
If ewkno < i Then
dater(1, i) = ""
Else
dater(1, i) = "*"
End If
End If
Next i
Application.EnableEvents = False
Range(Cells(2, 4), Cells(2, 56)) = dater
End If
Application.EnableEvents = True
End Sub
Note I haven't taken account of what happens if the start datea nd end date are in different years.