VB help

Posted on 2012-09-19
Last Modified: 2012-09-19
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

If the code above works out the first monday of each month (C2) & the last friday (C3)

What would be the code to work out the same for last month?

Question by:Kiwi-123
    1 Comment
    LVL 13

    Accepted Solution

    dtFirst = DateSerial(Year(Date), Month(Date) - 1, 1)
            dtLast = DateSerial(Year(Date), Month(Date), 0)

    ^ those 2 lines would change as such

    You may rename them to get last month

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
    This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now