• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 475
  • Last Modified:

command button help

Sorry please can you help me list the 1st and last day of the month; at the moment I got the 1st monday and last friday.

Private Sub CommandButton1_Click()

Dim dtFirst As Date
Dim dtLast As Date

        dtFirst = DateSerial(Year(Date), Month(Date), 1)
        dtLast = DateSerial(Year(Date), Month(Date) + 1, 0)
       
       Range("C2").Value = dtFirst + 6 - Weekday(dtFirst - 1, 3)
       
       Range("C3").Value = dtLast + 1 - Weekday(dtLast + 1 - 6)

End Sub
0
Kiwi-123
Asked:
Kiwi-123
1 Solution
 
Martin LissRetired ProgrammerCommented:
Take a look here.
0
 
nutschCommented:
Is this what you need?

Private Sub CommandButton1_Click()

Dim dtFirst As Date
Dim dtLast As Date

        dtFirst = DateSerial(Year(Date), Month(Date), 1)
        dtLast = DateSerial(Year(Date), Month(Date) + 1, 0)
       
       Range("C2").Value = dtFirst
       
       Range("C3").Value = dtLast

End Sub 

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now