LOOPING year and month

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

LOOPING year and month

Post by sal21 »

based current year...

i need to fill a combobox with the first day to last day for month may to september..

similar:

Private Sub APRI_PERIODI()

With Me.CPERIODI
.Clear
For K = 5 To 9
.AddItem first day of month & "-" & last day of month
Next K
End With

End Sub

and return:

01/05/2021-31/05/2021
01/06/2021-30/06/2021
...
01/09/2021-30/09/2021

User avatar
SpeakEasy
4StarLounger
Posts: 536
Joined: 27 Jun 2021, 10:46

Re: LOOPING year and month

Post by SpeakEasy »

Code: Select all

    For k = 5 To 9
        Debug.Print DateSerial(2021, k, 1) & "-" & DateSerial(2021, k + 1, 0)
    Next

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: LOOPING year and month

Post by sal21 »

SpeakEasy wrote:
06 Sep 2021, 12:32

Code: Select all

    For k = 5 To 9
        Debug.Print DateSerial(2021, k, 1) & "-" & DateSerial(2021, k + 1, 0)
    Next
WORK!
TKS.

CData
3StarLounger
Posts: 308
Joined: 24 Dec 2015, 16:41

Re: LOOPING year and month

Post by CData »

just a brief comment: as first day to last day for month may to september never changes
best practices would be to use a static table rather than rebuild each time... in terms of resource