milind_db
milind_db

Reputation: 1294

How to get list of months for specific number of years?

How do I get continued list of months for specific number of year?

e.g. if I entered 5 years, starts from January 2014 then below list will come which have January 2014 to December 2014 then again January 2015 to December 2015...till December 2019.

How can I get this any one have idea?

Upvotes: 0

Views: 60

Answers (1)

Gary's Student
Gary's Student

Reputation: 96753

Enter the number of years in cell B1 and run this small macro:

Sub MonthMaker()
    nYears = [b1]
    k = 1
    For i = 1 To nYears
        For j = 1 To 12
            Cells(k, 1) = DateSerial(2013 + i, j, 1)
            Cells(k, 1).NumberFormat = "mmmm yyyy"
            k = k + 1
        Next j
    Next i
End Sub

and if you do not wish to use VBA then enter the number of years in B1 and in A1 enter:

=IF(ROUNDDOWN((ROW()-1)/12,0)>$B$1-1,"",DATE(2014,ROW(),1))

and copy down.

Upvotes: 2

Related Questions