Here is the code with the comments.....
Private Sub Workbook_Open()
Dim ws As Worksheet
Dim rng As Range, cell As Range
Dim lr As Long, lc As Long, Alr As Long, ycnt As Long, i As Long, r As Long
Set ws = Sheets("Sheet1")
lr = ws.Cells(Rows.Count, 2).End(xlUp).Row '2 is the column index of first date column, in this case it is 2 for col. B
Alr = ws.Cells(Rows.Count, 1).End(xlUp).Row '1 is used for the col. A to check the last row with data
lc = ws.Cells(6, Columns.Count).End(xlToLeft).Column ' lc is the last column with date used in row 6
Set rng = ws.Range(ws.Cells(6, 2), ws.Cells(lr, lc))
r = 18 'r is the starting row in col. A where entries will be displayed, so change it as per your need
Application.ScreenUpdating = False
If Alr > 17 Then ws.Range(ws.Cells(18, 1), ws.Cells(Alr, 1)).Clear 'Clears result every time before displaying them again.
For i = 6 To lr ' i = 6 means that the actual data starts from row 6
Set rng = ws.Range(ws.Cells(i, 2), ws.Cells(i, lc)) ' sets range to have all the dates in a row, it will check for dates up to the last column.
For Each cell In rng
If Year(cell) = Year(Date) Then ycnt = ycnt + 1
Next cell
If ycnt > 0 Then
ws.Range("A" & r) = ws.Cells(i, 1) ' This will be the first cell in this case it is A18 where the output will be placed.
ws.Range("A" & r).Font.Color = vbRed ' These four lines are for the format of the result cells.
ws.Range("A" & r).Font.Bold = True
ws.Range("A" & r).Font.Size = 12
ws.Range("A" & r).HorizontalAlignment = xlCenter
r = r + 1
End If
ycnt = 0
Next i
Application.ScreenUpdating = True
End Sub
As per your sample workbook, since you want to show the result on row 18 onwards, so you can have max 16 rows for actual data.
The code looks for last column used in a row with date, so it will check the entire row for the dates.
Please make the changes in the code as per your requirement if any.
Bookmarks