Я добавил дополнительный код в существующий код
Sub ExtractYears()
'
Dim sc As Range
Dim Stdt As Date
Dim Edt As Date
Dim dDate As Date
Dim off As Integer
Dim offY As Integer
Dim year As Integer
'
Stdt = Range("B1") ' start date
Edt = Range("B2") ' end date
Set sc = Range("c2") ' start cell
'
' To clear the existing contents in Range D2 till end
Range("c2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Columns("F:G").ClearContents
'Offset
off = 0
offY = 0
'
For dDate = Stdt To Edt
If Format(dDate, "dd") <= "01" Then
year = Format(dDate, "yyyy")
sc.Offset(off, 0) = Format(dDate, "mmmm yyyy")
If sc.Offset(offY, 3) = vbNullString Or sc.Offset(offY, 3).Value = year Then
sc.Offset(offY, 3) = year
sc.Offset(offY, 4) = "Year" & offY + 1
Else
offY = offY + 1
sc.Offset(offY, 3) = year
sc.Offset(offY, 4) = "Year" & offY + 1
End If
off = off + 1
End If
Next dDate
'
sc.Resize(off, 1).NumberFormat = "mmmm yyyy"
'
End Sub