Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ezhov-da/41eafe1e340e9872d640c754a42b6a6c to your computer and use it in GitHub Desktop.
Save ezhov-da/41eafe1e340e9872d640c754a42b6a6c to your computer and use it in GitHub Desktop.
vba генерация списка месяцов по заданному диапазону и формату
Public Sub generate()
Dim collectionMonth As New Collection
Set collectionMonth = monthGenerator(12, "mmmm yyyy")
For i = 1 To collectionMonth.count
Debug.Print collectionMonth.Item(i)
Next i
End Sub
Public Function monthGenerator(countMonthFuture As Integer, frmtDateOut As String) As Collection
Dim collectionMonth As New Collection
Dim textMonth As String
Dim monthNum As Integer
monthNum = month(Now)
Dim yearNum As Integer
yearNum = year(Now)
Dim counter As Integer
Dim dateNow As Date
dateNow = CDate("01." & CStr(monthNum) & "." & CStr(yearNum))
Dim dateCurrent As Date
dateCurrent = dateNow
For counter = 0 To countMonthFuture
textMonth = Format(dateCurrent, frmtDateOut)
dateCurrent = dateCurrent + 31
collectionMonth.Add CStr(textMonth)
Next counter
Set monthGenerator = collectionMonth
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment