+ Reply to Thread
Results 1 to 6 of 6

Return value based on date range

  1. #1
    Registered User
    Join Date
    04-02-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    3

    Return value based on date range

    I am trying to assign custom Month value to a DATE based on the criteria if the date falls in between Start and End Date.

    Criteria:
    Start Date End Date Custom Month Value
    1/6/2014 2/2/2014 Jan-14
    2/3/2014 3/2/2014 Feb-14
    3/3/2014 4/6/2014 Mar-14
    4/7/2014 5/4/2014 Apr-14
    5/5/2014 6/1/2014 May-14

    Desired Output:
    DATE Custom Month Value
    1/11/2014 Jan-14
    3/1/2014 Feb-14
    5/4/2014 Apr-14

    The Criteria date ranges from 2000 to 2015.

    Would appreciate any advise on an optimal approach to achieve these results (without using if-else).

    Many Thanks

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Return value based on date range

    Try a user defined function

    Please Login or Register  to view this content.
    Open the VBA editor by hitting Alt F11.
    Insert a new module with Insert - Module
    Paste in the above function
    Go back to the sheet by hitting Alt F11.

    In C2, enter =CustomDate(A1,B1)

    Remember to save the workbook as a macro enabled workbook .xlsm
    Martin

  3. #3
    Registered User
    Join Date
    04-02-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Return value based on date range

    Thank you Martin for your suggestion, this definitely is a good option.

    However, my date ranges are from 2000 to 2015 and i will have to spell out 180 conditions to achieve this result. Could there be possibly a shorter way to achieve this.

    I do have a pattern in the date ranges: the no. of days b/w start date and end date for different months is as follows: 28, 28, 35, 28, 28, 35, 28, 28, 35, 28, 28, 35 (i.e. Mar, Jun, Sep, Dec have 5 weeks all other months have 4 weeks)

    Thanks again

  4. #4
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Return value based on date range

    Maybe formula solution

    =IF(AND(A2>=B2,B2<=A2),"",EDATE("1/14/2014",ROW($A1)-1))

    A
    B
    C
    1
    Srart Date End Date Custom format: mmm-yy
    2
    1/6/2014
    2/2/2014
    Jan-14
    3
    2/3/2014
    3/2/2014
    Feb-14
    4
    3/3/2014
    4/6/2014
    Mar-14
    5
    3/3/2014
    4/6/2014
    Apr-14
    6
    4/7/2014
    5/4/2014
    May-14
    7
    5/5/2014
    6/1/2014
    Jun-14
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  5. #5
    Registered User
    Join Date
    04-02-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Return value based on date range

    Thanks for your response AlKey, do I apply this as an array formulae? Does not seem to be working. The Criteria table is my example is a table that defines the criteria. I need the output in another table referencing Date.

    Quote Originally Posted by AlKey View Post
    Maybe formula solution

    =IF(AND(A2>=B2,B2<=A2),"",EDATE("1/14/2014",ROW($A1)-1))

    A
    B
    C
    1
    Srart Date End Date Custom format: mmm-yy
    2
    1/6/2014
    2/2/2014
    Jan-14
    3
    2/3/2014
    3/2/2014
    Feb-14
    4
    3/3/2014
    4/6/2014
    Mar-14
    5
    3/3/2014
    4/6/2014
    Apr-14
    6
    4/7/2014
    5/4/2014
    May-14
    7
    5/5/2014
    6/1/2014
    Jun-14

  6. #6
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Return value based on date range

    Maybe use the week number function to get the number of conditions down?


    Please Login or Register  to view this content.

+ 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] Return Value based upon date range
    By tsmor in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-06-2013, 11:05 PM
  2. [SOLVED] Return value based on ID and Date Range
    By just2cruz in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-28-2012, 07:15 PM
  3. Return 1 or 0 based on Date Range
    By kwjoh in forum Excel General
    Replies: 8
    Last Post: 03-04-2011, 10:55 PM
  4. Excel 2007 : Want to return a value based on date range
    By mlittle74 in forum Excel General
    Replies: 2
    Last Post: 04-03-2010, 01:23 PM
  5. Compare Dates To Date Range & Return Date Based On Outcome
    By gusmontoya in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-03-2008, 09: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