+ Reply to Thread
Results 1 to 13 of 13

Changing number of days in a month based on month chosen from a dropdown list.

Hybrid View

  1. #1
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Changing number of days in a month based on month chosen from a dropdown list.

    See if this helps
    Formula: copy to clipboard
    =DAY(DATE(E2,MONTH(DATEVALUE("1/"&D2&"/"&E2))+1,1)-1)

    Where D2 = Month as string
    E2 contains the year, this is needed to handle leap years.

    Or, if you are only interested in the current year, adapt the formula as Martin suggests
    Formula: copy to clipboard
    =DAY(DATE(YEAR(TODAY()),MONTH(DATEVALUE("1/"&D5&"/"&YEAR(TODAY())))+1,1)-1)


    This doesn't involve the Analysis ToolPak add-in. with 2003 and earlier
    Attached Files Attached Files
    Last edited by Marcol; 02-08-2013 at 10:17 AM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,421

    Re: Changing number of days in a month based on month chosen from a dropdown list.

    With the LOOKUP formula (Kevin's), you need to put the months in alphabetical order, with a corresponding shift of the days, i.e.:

    =LOOKUP(D1,{"Apr","Aug","Dec","Feb","Jan","Jul","Jun","Mar","May","Nov","Oct","Sep"},{30,31,31,28,31,31,30,31,31,30,31,30})

    although this would always give 28 days for February and not adjust for leap years.

    Hope this helps.

    Pete

+ 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