+ Reply to Thread
Results 1 to 5 of 5

Calendar Macro

  1. #1
    Registered User
    Join Date
    03-20-2007
    Posts
    3

    Question Calendar Macro

    Hi,
    I am trying to edit a Timesheet, what i am trying to do is, after entering the date in one cell (eg B3 mm/dd/yyyy, which will always be the first of each month) i would like to have a macro that lists out the days of that month in column A like from A10:A40 or 38 or 41 depending what the length of the month is. I am very new to creating and editing macros, can someone help me.

    Thanks.

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885
    Simple enough to do without a macro if you want:

    In B3 you'll enter the first day of a month, let's say 2/1/07.

    In A10 type the formula

    =$B$3+(ROW()-10)

    and fill that down to A37 (this will account for the first 28 days of the month).

    In A38 you need to check if it's February AND if it's a leap year. If it is a normal Feb, then A38 should be blank, but if it's a leap year then it should say 2/29. Use this formula:

    =IF(AND(MONTH($B$3)=2,MOD(YEAR($B$3),4)<>0),"",$B$3+(ROW()-10))

    In A39 you just need to check if it's February again, since all other months have at least 30 days. Use this formula:

    =IF(MONTH($B$3)=2,"",$B$3+(ROW()-10))

    Finally, in A40 you just need to check if it's not Feb, Apr, Jun, Sep or Nov, which only have 30 days. Use this formula:

    =IF(MONTH($B$3)={2,4,6,9,11},"",$B$3+(ROW()-10))

    There could be easier ways of doing this, but once you put these formulas in it's not like they'll need to be changed anytime soon. (I think in February of the year 2100 will be the next time this won't work, as years divisible by 100 do not have a leap day unless they are also divisible by 400, e.g. 2000, 2400. Of course, if you're still using this in the year 2100, get back to me and we'll fix you up.)

  3. #3
    Registered User
    Join Date
    03-20-2007
    Posts
    3
    thanks very much, worked great, there only one small thing though, on the row i enter the following
    =IF(MONTH($B$3)={2,4,6,9,11},"",$B$3+(ROW()-10))
    for the 4th, 6th, 9th, and 11th months it displays the day for the following month, for feb however it's empty. why is this?


    tanks

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885
    Sorry, I guess you can't use array constants in non-array formulas. Try this instead:

    =IF(OR(MONTH($B$3)=2,MONTH($B$3)=4,MONTH($B$3)=6,MONTH($B$3)=9,MONTH($B$3)=11),"",$B$3+(ROW()-10))

  5. #5
    Registered User
    Join Date
    03-20-2007
    Posts
    3

    Thumbs up

    Thanks Alot.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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