?
Solved

command button date

Posted on 2012-09-16
1
Medium Priority
?
459 Views
Last Modified: 2012-09-16
Please can you help,

I would like a command button which displays the following date:-

C2 = Monday of the current week
C3 = Friday of the current week

Then command button two

C2 = 1st Monday of the current month
C3 = Last friday of the current month
0
Comment
Question by:Kiwi-123
1 Comment
 
LVL 35

Accepted Solution

by:
Norie earned 2000 total points
ID: 38403885
Do you mean put those values in C2 and C3?
Private Sub CommandButton1_Click()

      Range("C2").Value = Date - Weekday(Date, 3)
      Range("C3").Value = Date - Weekday(Date, 3) + 4

End Sub

Private Sub CommandButton2_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

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

831 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