ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Listing months between two dates (https://www.excelbanter.com/excel-programming/410976-listing-months-between-two-dates.html)

klysell

Listing months between two dates
 
Hi,

I have a start and an end date. I need to create a list of months between
two dates. For example, if I have a start date (A13) of April 1st, 2008 and
an end date (A14) of October 31st, 2008, I need a list starting in B19 with
the first month being "April", the second being "May" in B20, etc. to the
seventh being "October" in B25. I need some code to parse the months between
any two dates.

Thanks in advance,
Kent Lysell
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557

merjet

Listing months between two dates
 
Put the code below in the module for the worksheet.
It's only for the start and end months being in the
same calendar year. It should be pretty easy to modify
to cross calendar years. No error trapping either.

Hth,
Merjet


Private Sub Worksheet_Change(ByVal Target As Range)
Dim iMo As Integer
If Target.Address = "$A$13" Or Target.Address = "$A$14" Then
Range("B19:B30").Clear
Do
Cells(19 + iMo, 2) = MonthName(iMo + Month(Range("A13")))
iMo = iMo + 1
Loop Until Month(Range("A13")) + iMo - 1 = Month(Range("A14"))
End If
End Sub




All times are GMT +1. The time now is 02:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com