Last active
March 10, 2019 12:18
-
-
Save ezhov-da/41eafe1e340e9872d640c754a42b6a6c to your computer and use it in GitHub Desktop.
vba генерация списка месяцов по заданному диапазону и формату
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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