+ Reply to Thread
Results 1 to 4 of 4

calculating month to date, year to date, week to date

  1. #1
    Registered User
    Join Date
    09-01-2011
    Location
    Austria
    MS-Off Ver
    Excel 2007
    Posts
    78

    calculating month to date, year to date, week to date

    I've got two cells with a beginning date, and another with an end date.

    I'm assigning macros to buttons labelled "WTD", "YTD", "MTD", i.e. week to date, year to date, month to date.

    I can work out month to date in formulas pretty easily. It's =DATE(YEAR(today()),MONTH(today))-1,DAY(today))). So cell A1 is today(), A2 is =DATE(YEAR(today()),MONTH(today))-1,DAY(today))

    However, I have no idea how to do this in VBA. I've been playing around.


    Sub Button4_Click()

    ActiveSheet.Range("A1").Value = Date - DateSerial(Year(date), Month(Date)-1, Day(Date))
    ActiveSheet.Range("A2").Value = Date

    End Sub
    This doesn't work the same way as in formulas.

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: calculating month to date, year to date, week to date

    Try the DATEADD() function....

  3. #3
    Registered User
    Join Date
    09-01-2011
    Location
    Austria
    MS-Off Ver
    Excel 2007
    Posts
    78

    Re: calculating month to date, year to date, week to date

    what about calculating of WTD. Is there anyway to just grab business days? E.g. if it's a monday and I click WTD I want to go back to last monday.

  4. #4
    Registered User
    Join Date
    09-01-2011
    Location
    Austria
    MS-Off Ver
    Excel 2007
    Posts
    78

    Re: calculating month to date, year to date, week to date

    So here's what I managed to get. But I can't figure out how to do an actual Month-TO-DATE, or week-TO-DATE.

    Please Login or Register  to view this content.

    Ideally, If I call WTD function, it should just go to the start of the month. WTD function... should go to the start of the week, e.g. if it's Thursday, it'll go Monday. If it's FRI-SUN it'll go back to monday....
    YTD same thing. if it's 06/06/2013, it'll go 01/01/2013....

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 12-15-2011, 05:32 AM
  2. how to insert month date year and day of week
    By Sachi Noma in forum Excel General
    Replies: 3
    Last Post: 05-18-2006, 10:10 PM
  3. [SOLVED] how to insert month date year and day of week
    By Sachi Noma in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 05-18-2006, 10:10 PM
  4. Replies: 1
    Last Post: 08-23-2005, 11:42 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1