+ Reply to Thread
Results 1 to 19 of 19

Formula to return End OF Month date with non-calendar month lengths.

  1. #1
    Registered User
    Join Date
    04-12-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    30

    Exclamation Formula to return End OF Month date with non-calendar month lengths.

    Hi gurus!
    I have run into a problem that i feel should be easier to solve than it seems.

    Scenario: I have a spreadsheet that is using a given date to show numbers from that date by referencing a day-by-day report. Most values can be gotten by using VLOOKUP but there is a problem.
    One value i need to get returned from the report is the End Of Month date based on the given date (i.e. if i enter 2014-04-25 it should give me 2014-04-30). This works fine by just using the EOMONTH-function in Excel.
    However, for a specific data-report, each month is not listed as the calendar month but rather a custom length where each months always have 7-day weeks.

    In the attached example file i have noted that on "Sheet1", in cell B5 i enter a date and based on that date cell B2 should return the End Of Month date.
    On "Sheet2" i have listed an example of two months and how they are listed in the data-report that is to be used to return the date in B2. As you can see, months end on different dates so EOMONTH cannot be used.

    I then tried using HLOOKUP in this kind of formula: =HLOOKUP("Month"&" "&TEXT(I3;"[$-409]MMMM");'Sheet2'!$A:$B;9;FALSE). The lookup works so that it finds the cell called "Month XXXX" but then i need to get the formula to step upwards and return the first date it finds. Here is where i can't figure out how to do it since it isn't always the first cell above the cell "Month XXXX", it will be either the First or the Second one.

    My thought is, can the "row_index_num" part of HLOOKUP be entered in the form of a formula or must it always be a number? Or do you have something completely differnt to suggest?

    I hope you guys can help!
    Attached Files Attached Files

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Formula to return End OF Month date with non-calendar month lengths.

    Please confirm the expected result for the given dates for testing purpose.

    03/05/2014

    07/05/2014

    13/05/2014

    25/05/2014


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    04-12-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Formula to return End OF Month date with non-calendar month lengths.

    Quote Originally Posted by :) Sixthsense :) View Post
    Please confirm the expected result for the given dates for testing purpose.

    03/05/2014
    07/05/2014
    13/05/2014
    25/05/2014
    Hi!

    03/05/2014
    07/05/2014
    13/05/2014
    These should all return the date 23/05/2014 as according to Sheet2 calendar they are part of the Month of May.


    25/05/2014
    This should return the date 27/06/2014 as according to Sheet2 calendar they are part of the Month of June.

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Formula to return End OF Month date with non-calendar month lengths.

    It will be very easy to pick the results (Month Name) if it stored in the next column (column-B) )

  5. #5
    Registered User
    Join Date
    04-12-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Formula to return End OF Month date with non-calendar month lengths.

    Quote Originally Posted by :) Sixthsense :) View Post
    It will be very easy to pick the results (Month Name) if it stored in the next column (column-B) )
    Hi,
    For sure, but no, that isn't an option.

  6. #6
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,585

    Re: Formula to return End OF Month date with non-calendar month lengths.

    Pl see attached file.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    04-12-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Formula to return End OF Month date with non-calendar month lengths.

    Quote Originally Posted by kvsrinivasamurthy View Post
    Pl see attached file.
    That is amazing, just what i need! Thank you mate!

    There is only one problem.. when i save your file and open it, it displays the correct date on the first sheet like it should but when i choose to edit the file so i can use it, the cell B2 changes to "#N/A". When i check the steps of the formula i get that annoying "The cell currently being evaluated contains a constant". I didn't change any formatting or other setting, just choose to enable editing for the file.
    Btw, i'm running Excel 2010.

    The parts of the formula that gives that error are these two:
    IF(MATCH($B$5;Sheet2!$A$1:$A$75;0)<MATCH("Month "&TEXT($B$5;"mmmm");Sheet2!$A$1:$A$75;0);INDEX(Sheet2!$A$1:$A$75;MATCH("Month "&TEXT($B$5;"mmmm");Sheet2!$A$1:$A$75;0)-2);INDEX(Sheet2!$A$1:$A$75;MATCH("Month "&TEXT(EOMONTH($B$5;1);"mmmm");Sheet2!$A$1:$A$75;0)-2))

    The evaluation of the above cell reference shows as 41785.

    Any ideas?? I've seen that error before and haven't fully understood why it keeps happening.
    Last edited by Snoddas; 05-09-2014 at 04:10 AM.

  8. #8
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,585

    Re: Formula to return End OF Month date with non-calendar month lengths.

    Try formatting the cell for Date.
    OR Change Formula as
    Please Login or Register  to view this content.
    Last edited by kvsrinivasamurthy; 05-09-2014 at 05:59 AM.

  9. #9
    Registered User
    Join Date
    04-12-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Formula to return End OF Month date with non-calendar month lengths.

    Quote Originally Posted by kvsrinivasamurthy View Post
    Try formatting the cell for Date.
    OR Change Formula as
    Please Login or Register  to view this content.
    Hi,
    It is already formatted as Date. Change it to General -> clicked OK -> change it back to Date -> clicked OK. Same error.
    I changed the formula and changed it back -> pressed Enter. Same error.
    I saved and re-opened the file, same error.

    This is a really annoying error, i can't seem to get rid of it. Any more ideas would be appreciated.

  10. #10
    Registered User
    Join Date
    04-12-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Formula to return End OF Month date with non-calendar month lengths.

    Saw your new formula suggestion. Tried it but still get the same error. Any other ideas?

  11. #11
    Registered User
    Join Date
    10-04-2013
    Location
    Bornholm, Danmark
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Formula to return End OF Month date with non-calendar month lengths.


  12. #12
    Registered User
    Join Date
    04-12-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Formula to return End OF Month date with non-calendar month lengths.

    Tack Bjarne! Sadly that didn't help, i still can't use the formula or even just press F2 on B2 and then ENTER without any changes. It directly results in #N/A.

  13. #13
    Registered User
    Join Date
    10-04-2013
    Location
    Bornholm, Danmark
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Formula to return End OF Month date with non-calendar month lengths.

    it works here are you using english or swedis ?

  14. #14
    Registered User
    Join Date
    10-04-2013
    Location
    Bornholm, Danmark
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Formula to return End OF Month date with non-calendar month lengths.

    in sheet2 you most chenge it to english month name i use danish my be it is ther

  15. #15
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,585

    Re: Formula to return End OF Month date with non-calendar month lengths.

    Pl upload your file.

  16. #16
    Registered User
    Join Date
    10-04-2013
    Location
    Bornholm, Danmark
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Formula to return End OF Month date with non-calendar month lengths.

    you can download it it in #11

  17. #17
    Registered User
    Join Date
    10-04-2013
    Location
    Bornholm, Danmark
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Formula to return End OF Month date with non-calendar month lengths.

    here it is :
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    04-12-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Formula to return End OF Month date with non-calendar month lengths.

    Quote Originally Posted by BjarneHansen View Post
    it works here are you using english or swedis ?
    I realized i forgot to mention something. I use my computer with an English OS and English Regional settings. However, my Office is Swedish so the formulas use Swedish as Excel formulas use the software language. So i also realized i forgot to add the English code "[$-409]" for all the TEXT function references to Month. I have changed them and also changed the month names on Sheet2 to English in your file Bjarne, but still i can't get rid of the #N/A error that is indicating it's the $B$5 references that are incorrect. Suggestions guys?

  19. #19
    Registered User
    Join Date
    04-12-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Formula to return End OF Month date with non-calendar month lengths.

    I found it! I changed all the "mmmm" references to upper-case ("MMMM") and presto, it worked

    Thank you for all your help guys!

+ 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. [SOLVED] Calendar Formula- Date given/add 90 days/ defult - 1st day next month
    By Gower Girl in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-24-2013, 06:21 PM
  2. [SOLVED] Formula to Relist Ranges by Month Opening instead of Calendar Month
    By investmentbanker in forum Excel General
    Replies: 3
    Last Post: 05-18-2012, 01:33 PM
  3. Replies: 3
    Last Post: 01-18-2008, 09:09 PM
  4. Replies: 3
    Last Post: 09-25-2007, 10:26 AM
  5. [SOLVED] is there a formula to generate a calendar month date rather than .
    By lmurray in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-21-2005, 12:06 PM

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