+ Reply to Thread
Results 1 to 20 of 20

Find out the earliest date

  1. #1
    Registered User
    Join Date
    08-29-2008
    Location
    Virginia
    Posts
    48

    Find out the earliest date

    I have two columns in a table; Plan and Date.

    Plan Date
    A 01/02/03
    B 12/08/05
    C 02/04/06
    C 06/04/07
    C 06/04/07

    Now I want the third column, also a date, so that it returns the earliest date for the repeating plan type.

    Plan Date New Date
    A 01/02/03 01/02/03
    B 12/08/05 12/08/05
    C 02/04/06 02/04/06
    C 06/04/07 02/04/06
    C 06/04/07 02/04/06

    I would appreciate any help. Thank you.

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

    Re: Find out the earliest date

    Try this user defined function.

    Please Login or Register  to view this content.

    Insert a new module by hitting Insert - Module

    Paste the functioninto the empty sheet

    Hit ALT F11 to get back to the worksheet.

    Paste

    Please Login or Register  to view this content.
    into cell C2 and copy down.
    Martin

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Find out the earliest date

    In b2 and copy down,

    =min(if(a$2:a$6=a2, b$2:b$6))

    The formula MUST be confirmed with Ctrl+Shift+Enter rather than just Enter.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Find out the earliest date

    Try this array formula

    =MIN(IF($A$2:$A$20=A2,$B$2:$B$20))

  5. #5
    Registered User
    Join Date
    08-29-2008
    Location
    Virginia
    Posts
    48

    Re: Find out the earliest date

    Thank you all for the help. It does the job but I was thinking in terms of VBA code. I wanted to integrate it as a part of my macro that does some other things with a push of a button. Is there a command equivalent to "MIN" in VBA?

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Find out the earliest date

    Maybe
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-29-2008
    Location
    Virginia
    Posts
    48

    Re: Find out the earliest date

    Thanks again.

    Continuing with the issue. Now I have one more condition to match.

    Plan Plan Type Date
    A M 9/12/2002
    B M 12/11/2003
    C M 4/5/2006
    C M 3/4/2007
    C M 3/4/2007
    C S 4/5/2004
    C S 3/4/2007

    This time I have to return earliest date for repeating Plan that have M plan type.

    Plan Plan Type Date New Date
    A M 9/12/2002 9/12/2002
    B M 12/11/2003 12/11/2003
    C M 4/5/2006 4/5/2006
    C M 3/4/2007 4/5/2006
    C M 3/4/2007 4/5/2006
    C S 4/5/2004 4/5/2004
    C S 3/4/2007 3/4/2007

    I tried following code but didn't get it to work
    Please Login or Register  to view this content.
    Am I missing something?

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Find out the earliest date

    AND evaluates the entire array and returns a single result; you want sequential individual evaluations.

    =MIN( IF($A$2:$A$8 = A2, IF(B$2:B$8 = "M", C$2:C$8) ) )

  9. #9
    Registered User
    Join Date
    08-29-2008
    Location
    Virginia
    Posts
    48

    Re: Find out the earliest date

    I tried that but I still am not getting the desired result. It is also considering "S" plan types.

    Plan Plan Type Date
    A M 9/12/2002 9/12/02
    B M 12/11/2003 12/11/03
    C M 4/5/2006 4/5/06
    C M 3/4/2007 4/5/06
    C M 3/4/2007 4/5/06
    C S 4/5/2004 4/5/06
    C S 3/4/2007 4/5/06

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Find out the earliest date

    Uh uh.

    Make sure it's array-entered.

  11. #11
    Registered User
    Join Date
    08-29-2008
    Location
    Virginia
    Posts
    48

    Re: Find out the earliest date

    I am embarrased to say but can you please explain what you mean by "array entered"?

    If it means ctrl + shift + enter, then I did it but with same result.
    Last edited by samirz10; 02-26-2009 at 09:35 PM.

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Find out the earliest date

    With the cursor in the formula bar, hold down Ctrl and Shift, then press Enter. You'll know you did it correctly if curly braces appear around the formula in the Formula Bar; you cannot type in the braces directly.

  13. #13
    Registered User
    Join Date
    08-29-2008
    Location
    Virginia
    Posts
    48

    Re: Find out the earliest date

    Yes, I did exactly the same but again with the same result. I just don't get it. If it is not much of a hassle, could you try it and see why its not working? I would really appreciate it.

    Thank you.

  14. #14
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Find out the earliest date

    See attached.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    08-29-2008
    Location
    Virginia
    Posts
    48

    Re: Find out the earliest date

    Thank you for quick response. But if you noticed, dates for two records in the end (Plan = C and Plan Type = S) also changed. I only need to change the dates for those records that meet both criteria; (i.e., Plan = C and Plan Type = M). The last two rows should have original date.

  16. #16
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Find out the earliest date

    Then change the formula to =MIN( IF($A$1:$A$7 = "C", IF(B$1:B$7 = "M", C$1:C$7) ) )

    I'm losing the bubble, here.

  17. #17
    Registered User
    Join Date
    08-29-2008
    Location
    Virginia
    Posts
    48

    Re: Find out the earliest date

    Well, there are several plans that are repeated, so I can't hard code it.

    I guess I'll just go through the table manually and change the dates. I would like thank you for your time. You've been a great help.

  18. #18
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Find out the earliest date

    There's no need to hard code it, it just needs a methodical implementation, and I can't tell where you're trying to go.

    If you have a large amount of data (which you must, or we'd both be wasting our time), post a larger sample and your desired output for that entire sample. Then we can fix it for the general case.

    What you've provided so far isn't enough (for me, anyway) to see the whole picture.

  19. #19
    Registered User
    Join Date
    08-29-2008
    Location
    Virginia
    Posts
    48

    Re: Find out the earliest date

    Shg,

    I have attached a sample of my .xls file and let me try to explain what I am trying to do again.

    I have 4 fields; Plan Title, Plan Type, Approval Date and New Date.

    For every Plan Title that is repeated (Ex. Berkshire Regional Planning Commission) and has Plan Type "M", New Date should be populated with the earliest Approval Date (04/26/05). But if the same Plan Title has "S" or any other Plan Type, it should ignore them (New Date should be populated with original Approval Date)
    Attached Files Attached Files

  20. #20
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Find out the earliest date

    Still not perfectly clear to me, but maybe this. If not, point out a counterexample and explain why it's wrong.

    As before, you MUST confirm the formula with Ctrl+Shift+Enter. Enter in D2, then copy down:

    =IF(B2 <> "M", C2, MIN(IF($A$2:$A$152 = A2, $C$2:$C$152) ) )

+ 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