Closed Thread
Results 1 to 91 of 91

Max date

  1. #1
    Maxi
    Guest

    Re: Max date

    Works !!!

    Thanx


  2. #2
    kk
    Guest

    Re: Max date

    Hi!

    I didn't read you first post so I assume your data range is A1:C1

    In I1, type =Max(Day($A2:$G2))

    This is an array formula so you need to confirmed it by Ctrl+Shift+Enter.



    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    You didn't understand my question I guess

    I am looking for a formula in cell I1 and I2

    First of all there are two records.

    Row1:
    There are two dates for May and 9th May is the first date = 9.
    There are two dates for Jun and 1st June is the first date = 1.
    There are three dates for July and 13th July is the first date = 13.
    Therefore the max value is 13 (out of 9 1 and 13) so I1 will contain 13

    Row2:
    There is one date for May and 13th May is the first date = 13.
    There are three dates for Jun and 6th June is the first date = 6.
    There are three dates for July and 1st July is the first date = 1.
    Therefore the max value is 13 (out of 13 6 and 1) so I1 will contain 13

    Maxi



  3. #3
    Maxi
    Guest

    Re: Max date

    No Biff, the answer is not 20.

    I am looking for an answer that give 13. Look at the corrected
    question. The first question was incorrectly framed.

    Maxi


  4. #4
    Maxi
    Guest

    Re: Max date

    There is a big confusion.

    Let me start over again.......... Now don't look at any previous
    posts.... This is the final and only read this one.

    This is what I have in range A2:G2
    9-May 17-May 1-Jun 15-Jun 13-Jul 14-Jul 18-Jul 13
    13-May 6-Jun 12-Jun 20-Jun 1-Jul 16-Jul 20-Jul 13

    I want to check the first occurring date of each month and then compare
    it with the next occurring first date of the next month and so on and
    then find out the max date.

    Eg.
    First row:
    First date in May 9th, in June 1st, in Jul 13th hence the result should
    be 13
    Second row:
    First date in May 13th, in June 6th, in Jul 1st hence the result should

    be 13

    To make it more simpler:
    Row1:
    There are two dates for May and 9th May is the first date = 9.
    There are two dates for Jun and 1st June is the first date = 1.
    There are three dates for July and 13th July is the first date = 13.
    Therefore the max value is 13 (out of 9 1 and 13) so I1 will contain 13


    Row2:
    There is one date for May and 13th May is the first date = 13.
    There are three dates for Jun and 6th June is the first date = 6.
    There are three dates for July and 1st July is the first date = 1.
    Therefore the max value is 13 (out of 13 6 and 1) so I1 will contain 13


    The answer in I1 and I2 both should come to 13

    Maxi


  5. #5
    Biff
    Guest

    Re: Max date

    Hi!

    Try this....

    Entered as an array using the key combo of CTRL,SHIFT,ENTER:

    =MAX(DAY(A2:G2))

    Biff

    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    > This is what I have in range A2:G2
    > 9-May 17-May 1-Jun 15-Jun 13-Jul 14-Jul 18-Jul 18
    > 13-May 6-Jun 12-Jun 20-Jun 1-Jul 16-Jul 20-Jul 20
    >
    > I want to see the max date monthwise and then find out the max of all
    > the dates.
    >
    > Eg. In Row 1 max figure for May is 17, June 15, July 18 hence Answer =
    > 18
    > In Row 1 max figure for May is 13, June 20, July 20 hence Answer = 20
    >
    > Maxi
    >




  6. #6
    Maxi
    Guest

    Re: Max date

    You didn't understand my question I guess

    I am looking for a formula in cell I1 and I2

    First of all there are two records.

    Row1:
    There are two dates for May and 9th May is the first date = 9.
    There are two dates for Jun and 1st June is the first date = 1.
    There are three dates for July and 13th July is the first date = 13.
    Therefore the max value is 13 (out of 9 1 and 13) so I1 will contain 13

    Row2:
    There is one date for May and 13th May is the first date = 13.
    There are three dates for Jun and 6th June is the first date = 6.
    There are three dates for July and 1st July is the first date = 1.
    Therefore the max value is 13 (out of 13 6 and 1) so I1 will contain 13

    Maxi


  7. #7
    Biff
    Guest

    Re: Max date

    Hi!

    I understand what you want. It's not so simple!

    Will the months always be the same? May, June and July?

    Will the dates always be in ascending order?

    Biff

    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    > There is a big confusion.
    >
    > Let me start over again.......... Now don't look at any previous
    > posts.... This is the final and only read this one.
    >
    > This is what I have in range A2:G2
    > 9-May 17-May 1-Jun 15-Jun 13-Jul 14-Jul 18-Jul 13
    > 13-May 6-Jun 12-Jun 20-Jun 1-Jul 16-Jul 20-Jul 13
    >
    > I want to check the first occurring date of each month and then compare
    > it with the next occurring first date of the next month and so on and
    > then find out the max date.
    >
    > Eg.
    > First row:
    > First date in May 9th, in June 1st, in Jul 13th hence the result should
    > be 13
    > Second row:
    > First date in May 13th, in June 6th, in Jul 1st hence the result should
    >
    > be 13
    >
    > To make it more simpler:
    > Row1:
    > There are two dates for May and 9th May is the first date = 9.
    > There are two dates for Jun and 1st June is the first date = 1.
    > There are three dates for July and 13th July is the first date = 13.
    > Therefore the max value is 13 (out of 9 1 and 13) so I1 will contain 13
    >
    >
    > Row2:
    > There is one date for May and 13th May is the first date = 13.
    > There are three dates for Jun and 6th June is the first date = 6.
    > There are three dates for July and 1st July is the first date = 1.
    > Therefore the max value is 13 (out of 13 6 and 1) so I1 will contain 13
    >
    >
    > The answer in I1 and I2 both should come to 13
    >
    > Maxi
    >




  8. #8
    Maxi
    Guest

    Re: Max date

    No, months can be different. There can be a month with 2004 as year and
    same month with 2005. Yes, dates will always be in ascending order.

    If not a formula, even a VBA would do. I am tired of thinking a logic
    on how to get this issue resolved.

    Maxi


  9. #9
    Biff
    Guest

    Re: Max date

    Hi!

    Here's one way but requires a helper row...

    Dates in A2:G2

    In A3 enter this formula and copy across to G3:

    =IF(SUMPRODUCT(--(MONTH($A2:A2)=MONTH(A2)))>1,"",1)

    Formula for the max day (still an array formula):

    =MAX(DAY(IF(A3:G3=1,A2:G2)))

    You can use this until someone comes up with something better. I'll keep
    trying for something better that doesn't need a helper. I'm close!

    Biff

    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    > No, months can be different. There can be a month with 2004 as year and
    > same month with 2005. Yes, dates will always be in ascending order.
    >
    > If not a formula, even a VBA would do. I am tired of thinking a logic
    > on how to get this issue resolved.
    >
    > Maxi
    >




  10. #10
    Maxi
    Guest

    Re: Max date

    Good logic but as you said without the helper would be an efficient way
    of doing it. Thanks for your efforts even this formula will work out.
    Please let me know if you get something better.

    Maxi


  11. #11

    Re: Max date

    I have also tried to do this as an array and drawn a blank
    however a UDF if it would help

    Function MaxDate(myRange As Range) As Integer

    Dim myarray(1 To 12) As Integer
    For Each cell In myRange
    If myarray(Month(cell.Value)) <> 0 Then
    myarray(Month(cell.Value)) = _
    WorksheetFunction.Min(Day(cell.Value),
    myarray(Month(cell.Value)))
    Else
    myarray(Month(cell.Value)) = Day(cell.Value)
    End If
    Next cell

    MaxDate = WorksheetFunction.Max(myarray)

    End Function

    Feels like brute force though

    hth RES

  12. #12
    Biff
    Guest

    Re: Max date

    Hi!

    Don't know anything about VBA but when I try this I get a compile syntax
    error with this section highlighted:

    myarray(Month(cell.Value)) = _
    WorksheetFunction.Min(Day(cell.Value),

    Biff

    <[email protected]> wrote in message
    news:[email protected]...
    >I have also tried to do this as an array and drawn a blank
    > however a UDF if it would help
    >
    > Function MaxDate(myRange As Range) As Integer
    >
    > Dim myarray(1 To 12) As Integer
    > For Each cell In myRange
    > If myarray(Month(cell.Value)) <> 0 Then
    > myarray(Month(cell.Value)) = _
    > WorksheetFunction.Min(Day(cell.Value),
    > myarray(Month(cell.Value)))
    > Else
    > myarray(Month(cell.Value)) = Day(cell.Value)
    > End If
    > Next cell
    >
    > MaxDate = WorksheetFunction.Max(myarray)
    >
    > End Function
    >
    > Feels like brute force though
    >
    > hth RES




  13. #13
    Biff
    Guest

    Re: Max date

    Hi!

    Not real elegant but it works without the need for the helper:

    Dates in A2:G2

    Array entered:

    =MAX(DAY(MIN(IF(MONTH(A2:G2)=MONTH(A2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(B2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(C2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(D2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(E2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(F2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(G2),A2:G2))))

    If the months are always a series of three and they're consecutive:

    =MAX(DAY(MIN(IF(MONTH(A2:G2)=MONTH(A2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(A2)+1,A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(A2)+2,A2:G2))))

    If you don't mind hardcoding the months:

    =MAX(DAY(MIN(IF(MONTH(A2:G2)=5,A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=6,A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=7,A2:G2))))

    Couldn't figure out how do do this as a single array statement.

    Biff

    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    > Good logic but as you said without the helper would be an efficient way
    > of doing it. Thanks for your efforts even this formula will work out.
    > Please let me know if you get something better.
    >
    > Maxi
    >




  14. #14
    kk
    Guest

    Re: Max date

    Hi Maxi,

    Assume your data range A1:C1

    In D1, try this array formula
    =MAX(DAY($A1:$C1))

    Confirm the formula by Ctrl+Shift+Enter

    Does it help?


    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    Sorry. I framed the question incorrectly.

    I want to check the first occurring date of each month and then compare
    it with the next occurring first date of the next month in the array
    and then find out the max date.

    Eg.
    First row:
    First date in May 9th, in June 1st, in Jul 13th hence the result should
    be 13

    Second row:
    First date in May 13th, in June 6th, in Jul 1st hence the result should
    be 13

    Maxi



  15. #15

    Re: Max date

    Biff
    The problem is due to the wonderful line wrapping that happens with a post

    > myarray(Month(cell.Value)) = _
    > WorksheetFunction.Min(Day(cell.Value),
    > myarray(Month(cell.Value)))


    is all one line of code.
    The _ tells VBA to complie the next line as part of the current.
    Try it as

    myarray(Month(cell.Value)) = _
    WorksheetFunction.Min(Day(cell.Value), _
    myarray(Month(cell.Value)))

    Hopefully the newsgroup engines will not introduce any unforeseen wraps

  16. #16
    Maxi
    Guest

    Re: Max date

    Biff, I appreciate your efforts and all is working fine but the UDF
    from Robert is an efficient way of doing it.

    As far as speed of processing is concerned, I am not sure if UDF takes
    long time of the array formula.

    Robert, one question for you.

    I didn't understand the line Dim myarray(1 To 12) As Integer

    Why 1 to 12?

    Also the data what I gave was just a sample data. I have around 3160
    rows in my file. When I used Biff's suggestion, everything works fine
    but your UDF does not give me correct results for 366 rows out of 3160.


    In my file I have 3160 rows and 25+ columns. There can be less than 25
    columns in a row or there can be more. Few columns are BLANK but I
    guess your If myarray(Month(cell.Value)) <> 0 Then line will take care
    of it.

    I am just wondering why I am not getting correct result for 366 rows.
    Do I have to make changes in the Dim myarray(1 To 12) As Integer line?

    Maxi


  17. #17
    Maxi
    Guest

    Re: Max date

    Sorry. I framed the question incorrectly.

    I want to check the first occurring date of each month and then compare
    it with the next occurring first date of the next month in the array
    and then find out the max date.

    Eg.
    First row:
    First date in May 9th, in June 1st, in Jul 13th hence the result should
    be 13

    Second row:
    First date in May 13th, in June 6th, in Jul 1st hence the result should
    be 13

    Maxi


  18. #18

    Re: Max date

    Maxi
    The array
    > Dim myarray(1 To 12) As Integer

    is equivalent to myarray(jan to dec) and stores a day value in each.
    The reason you were getting incorrect results from the UDF I posted is I
    had not protected against blank cells
    A revised version is posted below.

    The logic is as follows
    Set up a data store for each possible month to hold the day value
    loop through each cell in the range in turn
    if there is a positive value in the cell continue if not skip to the next
    cell
    using the month value of the cell look in the array
    if the entry in the array is not 0 then make it equal to the lowest of
    either the current array value or the day value of the cell
    otherwise put in the day value of the cell
    when all the cells have been checked return the largest value in the array


    ***************************

    Function MaxDate(myRange As Range) As Integer

    Dim myarray(1 To 12) As Integer
    For Each cell In myRange
    If cell.Value > 0 Then
    If myarray(Month(cell.Value)) <> 0 Then
    myarray(Month(cell.Value)) = _
    WorksheetFunction.Min(Day(cell.Value), _
    myarray(Month(cell.Value)))
    Else
    myarray(Month(cell.Value)) = Day(cell.Value)
    End If
    End If
    Next cell

    MaxDate = WorksheetFunction.Max(myarray)

    End Function

    **************************

    I am sure some of the gurus could simplify the logic but for now I hope
    this does the trick.

    let us know if it works
    cheers RES

  19. #19
    Maxi
    Guest

    Re: Max date

    Biff, I appreciate your efforts and all is working fine but the UDF
    from Robert is an efficient way of doing it.

    As far as speed of processing is concerned, I am not sure if UDF takes
    long time of the array formula.

    Robert, one question for you.

    I didn't understand the line Dim myarray(1 To 12) As Integer

    Why 1 to 12?

    Also the data what I gave was just a sample data. I have around 3160
    rows in my file. When I used Biff's suggestion, everything works fine
    but your UDF does not give me correct results for 366 rows out of 3160.


    In my file I have 3160 rows and 25+ columns. There can be less than 25
    columns in a row or there can be more. Few columns are BLANK but I
    guess your If myarray(Month(cell.Value)) <> 0 Then line will take care
    of it.

    I am just wondering why I am not getting correct result for 366 rows.
    Do I have to make changes in the Dim myarray(1 To 12) As Integer line?

    Maxi


  20. #20
    Maxi
    Guest

    Re: Max date

    Sorry. I framed the question incorrectly.

    I want to check the first occurring date of each month and then compare
    it with the next occurring first date of the next month in the array
    and then find out the max date.

    Eg.
    First row:
    First date in May 9th, in June 1st, in Jul 13th hence the result should
    be 13

    Second row:
    First date in May 13th, in June 6th, in Jul 1st hence the result should
    be 13

    Maxi


  21. #21
    Maxi
    Guest

    Re: Max date

    Works !!!

    Thanx


  22. #22
    Maxi
    Guest

    Re: Max date

    There is a big confusion.

    Let me start over again.......... Now don't look at any previous
    posts.... This is the final and only read this one.

    This is what I have in range A2:G2
    9-May 17-May 1-Jun 15-Jun 13-Jul 14-Jul 18-Jul 13
    13-May 6-Jun 12-Jun 20-Jun 1-Jul 16-Jul 20-Jul 13

    I want to check the first occurring date of each month and then compare
    it with the next occurring first date of the next month and so on and
    then find out the max date.

    Eg.
    First row:
    First date in May 9th, in June 1st, in Jul 13th hence the result should
    be 13
    Second row:
    First date in May 13th, in June 6th, in Jul 1st hence the result should

    be 13

    To make it more simpler:
    Row1:
    There are two dates for May and 9th May is the first date = 9.
    There are two dates for Jun and 1st June is the first date = 1.
    There are three dates for July and 13th July is the first date = 13.
    Therefore the max value is 13 (out of 9 1 and 13) so I1 will contain 13


    Row2:
    There is one date for May and 13th May is the first date = 13.
    There are three dates for Jun and 6th June is the first date = 6.
    There are three dates for July and 1st July is the first date = 1.
    Therefore the max value is 13 (out of 13 6 and 1) so I1 will contain 13


    The answer in I1 and I2 both should come to 13

    Maxi


  23. #23

    Re: Max date

    Maxi
    The array
    > Dim myarray(1 To 12) As Integer

    is equivalent to myarray(jan to dec) and stores a day value in each.
    The reason you were getting incorrect results from the UDF I posted is I
    had not protected against blank cells
    A revised version is posted below.

    The logic is as follows
    Set up a data store for each possible month to hold the day value
    loop through each cell in the range in turn
    if there is a positive value in the cell continue if not skip to the next
    cell
    using the month value of the cell look in the array
    if the entry in the array is not 0 then make it equal to the lowest of
    either the current array value or the day value of the cell
    otherwise put in the day value of the cell
    when all the cells have been checked return the largest value in the array


    ***************************

    Function MaxDate(myRange As Range) As Integer

    Dim myarray(1 To 12) As Integer
    For Each cell In myRange
    If cell.Value > 0 Then
    If myarray(Month(cell.Value)) <> 0 Then
    myarray(Month(cell.Value)) = _
    WorksheetFunction.Min(Day(cell.Value), _
    myarray(Month(cell.Value)))
    Else
    myarray(Month(cell.Value)) = Day(cell.Value)
    End If
    End If
    Next cell

    MaxDate = WorksheetFunction.Max(myarray)

    End Function

    **************************

    I am sure some of the gurus could simplify the logic but for now I hope
    this does the trick.

    let us know if it works
    cheers RES

  24. #24
    Biff
    Guest

    Re: Max date

    Hi!

    I understand what you want. It's not so simple!

    Will the months always be the same? May, June and July?

    Will the dates always be in ascending order?

    Biff

    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    > There is a big confusion.
    >
    > Let me start over again.......... Now don't look at any previous
    > posts.... This is the final and only read this one.
    >
    > This is what I have in range A2:G2
    > 9-May 17-May 1-Jun 15-Jun 13-Jul 14-Jul 18-Jul 13
    > 13-May 6-Jun 12-Jun 20-Jun 1-Jul 16-Jul 20-Jul 13
    >
    > I want to check the first occurring date of each month and then compare
    > it with the next occurring first date of the next month and so on and
    > then find out the max date.
    >
    > Eg.
    > First row:
    > First date in May 9th, in June 1st, in Jul 13th hence the result should
    > be 13
    > Second row:
    > First date in May 13th, in June 6th, in Jul 1st hence the result should
    >
    > be 13
    >
    > To make it more simpler:
    > Row1:
    > There are two dates for May and 9th May is the first date = 9.
    > There are two dates for Jun and 1st June is the first date = 1.
    > There are three dates for July and 13th July is the first date = 13.
    > Therefore the max value is 13 (out of 9 1 and 13) so I1 will contain 13
    >
    >
    > Row2:
    > There is one date for May and 13th May is the first date = 13.
    > There are three dates for Jun and 6th June is the first date = 6.
    > There are three dates for July and 1st July is the first date = 1.
    > Therefore the max value is 13 (out of 13 6 and 1) so I1 will contain 13
    >
    >
    > The answer in I1 and I2 both should come to 13
    >
    > Maxi
    >




  25. #25
    Maxi
    Guest

    Re: Max date

    No, months can be different. There can be a month with 2004 as year and
    same month with 2005. Yes, dates will always be in ascending order.

    If not a formula, even a VBA would do. I am tired of thinking a logic
    on how to get this issue resolved.

    Maxi


  26. #26
    Biff
    Guest

    Re: Max date

    Hi!

    Not real elegant but it works without the need for the helper:

    Dates in A2:G2

    Array entered:

    =MAX(DAY(MIN(IF(MONTH(A2:G2)=MONTH(A2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(B2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(C2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(D2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(E2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(F2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(G2),A2:G2))))

    If the months are always a series of three and they're consecutive:

    =MAX(DAY(MIN(IF(MONTH(A2:G2)=MONTH(A2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(A2)+1,A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(A2)+2,A2:G2))))

    If you don't mind hardcoding the months:

    =MAX(DAY(MIN(IF(MONTH(A2:G2)=5,A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=6,A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=7,A2:G2))))

    Couldn't figure out how do do this as a single array statement.

    Biff

    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    > Good logic but as you said without the helper would be an efficient way
    > of doing it. Thanks for your efforts even this formula will work out.
    > Please let me know if you get something better.
    >
    > Maxi
    >




  27. #27
    Biff
    Guest

    Re: Max date

    Hi!

    Here's one way but requires a helper row...

    Dates in A2:G2

    In A3 enter this formula and copy across to G3:

    =IF(SUMPRODUCT(--(MONTH($A2:A2)=MONTH(A2)))>1,"",1)

    Formula for the max day (still an array formula):

    =MAX(DAY(IF(A3:G3=1,A2:G2)))

    You can use this until someone comes up with something better. I'll keep
    trying for something better that doesn't need a helper. I'm close!

    Biff

    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    > No, months can be different. There can be a month with 2004 as year and
    > same month with 2005. Yes, dates will always be in ascending order.
    >
    > If not a formula, even a VBA would do. I am tired of thinking a logic
    > on how to get this issue resolved.
    >
    > Maxi
    >




  28. #28

    Re: Max date

    Biff
    The problem is due to the wonderful line wrapping that happens with a post

    > myarray(Month(cell.Value)) = _
    > WorksheetFunction.Min(Day(cell.Value),
    > myarray(Month(cell.Value)))


    is all one line of code.
    The _ tells VBA to complie the next line as part of the current.
    Try it as

    myarray(Month(cell.Value)) = _
    WorksheetFunction.Min(Day(cell.Value), _
    myarray(Month(cell.Value)))

    Hopefully the newsgroup engines will not introduce any unforeseen wraps

  29. #29
    Maxi
    Guest

    Re: Max date

    Good logic but as you said without the helper would be an efficient way
    of doing it. Thanks for your efforts even this formula will work out.
    Please let me know if you get something better.

    Maxi


  30. #30

    Re: Max date

    I have also tried to do this as an array and drawn a blank
    however a UDF if it would help

    Function MaxDate(myRange As Range) As Integer

    Dim myarray(1 To 12) As Integer
    For Each cell In myRange
    If myarray(Month(cell.Value)) <> 0 Then
    myarray(Month(cell.Value)) = _
    WorksheetFunction.Min(Day(cell.Value),
    myarray(Month(cell.Value)))
    Else
    myarray(Month(cell.Value)) = Day(cell.Value)
    End If
    Next cell

    MaxDate = WorksheetFunction.Max(myarray)

    End Function

    Feels like brute force though

    hth RES

  31. #31
    Biff
    Guest

    Re: Max date

    Hi!

    Don't know anything about VBA but when I try this I get a compile syntax
    error with this section highlighted:

    myarray(Month(cell.Value)) = _
    WorksheetFunction.Min(Day(cell.Value),

    Biff

    <[email protected]> wrote in message
    news:[email protected]...
    >I have also tried to do this as an array and drawn a blank
    > however a UDF if it would help
    >
    > Function MaxDate(myRange As Range) As Integer
    >
    > Dim myarray(1 To 12) As Integer
    > For Each cell In myRange
    > If myarray(Month(cell.Value)) <> 0 Then
    > myarray(Month(cell.Value)) = _
    > WorksheetFunction.Min(Day(cell.Value),
    > myarray(Month(cell.Value)))
    > Else
    > myarray(Month(cell.Value)) = Day(cell.Value)
    > End If
    > Next cell
    >
    > MaxDate = WorksheetFunction.Max(myarray)
    >
    > End Function
    >
    > Feels like brute force though
    >
    > hth RES




  32. #32
    Maxi
    Guest

    Re: Max date

    You didn't understand my question I guess

    I am looking for a formula in cell I1 and I2

    First of all there are two records.

    Row1:
    There are two dates for May and 9th May is the first date = 9.
    There are two dates for Jun and 1st June is the first date = 1.
    There are three dates for July and 13th July is the first date = 13.
    Therefore the max value is 13 (out of 9 1 and 13) so I1 will contain 13

    Row2:
    There is one date for May and 13th May is the first date = 13.
    There are three dates for Jun and 6th June is the first date = 6.
    There are three dates for July and 1st July is the first date = 1.
    Therefore the max value is 13 (out of 13 6 and 1) so I1 will contain 13

    Maxi


  33. #33
    Maxi
    Guest

    Re: Max date

    No Biff, the answer is not 20.

    I am looking for an answer that give 13. Look at the corrected
    question. The first question was incorrectly framed.

    Maxi


  34. #34
    Biff
    Guest

    Re: Max date

    Hi!

    Try this....

    Entered as an array using the key combo of CTRL,SHIFT,ENTER:

    =MAX(DAY(A2:G2))

    Biff

    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    > This is what I have in range A2:G2
    > 9-May 17-May 1-Jun 15-Jun 13-Jul 14-Jul 18-Jul 18
    > 13-May 6-Jun 12-Jun 20-Jun 1-Jul 16-Jul 20-Jul 20
    >
    > I want to see the max date monthwise and then find out the max of all
    > the dates.
    >
    > Eg. In Row 1 max figure for May is 17, June 15, July 18 hence Answer =
    > 18
    > In Row 1 max figure for May is 13, June 20, July 20 hence Answer = 20
    >
    > Maxi
    >




  35. #35
    kk
    Guest

    Re: Max date

    Hi!

    I didn't read you first post so I assume your data range is A1:C1

    In I1, type =Max(Day($A2:$G2))

    This is an array formula so you need to confirmed it by Ctrl+Shift+Enter.



    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    You didn't understand my question I guess

    I am looking for a formula in cell I1 and I2

    First of all there are two records.

    Row1:
    There are two dates for May and 9th May is the first date = 9.
    There are two dates for Jun and 1st June is the first date = 1.
    There are three dates for July and 13th July is the first date = 13.
    Therefore the max value is 13 (out of 9 1 and 13) so I1 will contain 13

    Row2:
    There is one date for May and 13th May is the first date = 13.
    There are three dates for Jun and 6th June is the first date = 6.
    There are three dates for July and 1st July is the first date = 1.
    Therefore the max value is 13 (out of 13 6 and 1) so I1 will contain 13

    Maxi



  36. #36
    kk
    Guest

    Re: Max date

    Hi Maxi,

    Assume your data range A1:C1

    In D1, try this array formula
    =MAX(DAY($A1:$C1))

    Confirm the formula by Ctrl+Shift+Enter

    Does it help?


    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    Sorry. I framed the question incorrectly.

    I want to check the first occurring date of each month and then compare
    it with the next occurring first date of the next month in the array
    and then find out the max date.

    Eg.
    First row:
    First date in May 9th, in June 1st, in Jul 13th hence the result should
    be 13

    Second row:
    First date in May 13th, in June 6th, in Jul 1st hence the result should
    be 13

    Maxi



  37. #37
    kk
    Guest

    Re: Max date

    Hi Maxi,

    Assume your data range A1:C1

    In D1, try this array formula
    =MAX(DAY($A1:$C1))

    Confirm the formula by Ctrl+Shift+Enter

    Does it help?


    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    Sorry. I framed the question incorrectly.

    I want to check the first occurring date of each month and then compare
    it with the next occurring first date of the next month in the array
    and then find out the max date.

    Eg.
    First row:
    First date in May 9th, in June 1st, in Jul 13th hence the result should
    be 13

    Second row:
    First date in May 13th, in June 6th, in Jul 1st hence the result should
    be 13

    Maxi



  38. #38
    Maxi
    Guest

    Re: Max date

    Biff, I appreciate your efforts and all is working fine but the UDF
    from Robert is an efficient way of doing it.

    As far as speed of processing is concerned, I am not sure if UDF takes
    long time of the array formula.

    Robert, one question for you.

    I didn't understand the line Dim myarray(1 To 12) As Integer

    Why 1 to 12?

    Also the data what I gave was just a sample data. I have around 3160
    rows in my file. When I used Biff's suggestion, everything works fine
    but your UDF does not give me correct results for 366 rows out of 3160.


    In my file I have 3160 rows and 25+ columns. There can be less than 25
    columns in a row or there can be more. Few columns are BLANK but I
    guess your If myarray(Month(cell.Value)) <> 0 Then line will take care
    of it.

    I am just wondering why I am not getting correct result for 366 rows.
    Do I have to make changes in the Dim myarray(1 To 12) As Integer line?

    Maxi


  39. #39

    Re: Max date

    Biff
    The problem is due to the wonderful line wrapping that happens with a post

    > myarray(Month(cell.Value)) = _
    > WorksheetFunction.Min(Day(cell.Value),
    > myarray(Month(cell.Value)))


    is all one line of code.
    The _ tells VBA to complie the next line as part of the current.
    Try it as

    myarray(Month(cell.Value)) = _
    WorksheetFunction.Min(Day(cell.Value), _
    myarray(Month(cell.Value)))

    Hopefully the newsgroup engines will not introduce any unforeseen wraps

  40. #40

    Re: Max date

    Maxi
    The array
    > Dim myarray(1 To 12) As Integer

    is equivalent to myarray(jan to dec) and stores a day value in each.
    The reason you were getting incorrect results from the UDF I posted is I
    had not protected against blank cells
    A revised version is posted below.

    The logic is as follows
    Set up a data store for each possible month to hold the day value
    loop through each cell in the range in turn
    if there is a positive value in the cell continue if not skip to the next
    cell
    using the month value of the cell look in the array
    if the entry in the array is not 0 then make it equal to the lowest of
    either the current array value or the day value of the cell
    otherwise put in the day value of the cell
    when all the cells have been checked return the largest value in the array


    ***************************

    Function MaxDate(myRange As Range) As Integer

    Dim myarray(1 To 12) As Integer
    For Each cell In myRange
    If cell.Value > 0 Then
    If myarray(Month(cell.Value)) <> 0 Then
    myarray(Month(cell.Value)) = _
    WorksheetFunction.Min(Day(cell.Value), _
    myarray(Month(cell.Value)))
    Else
    myarray(Month(cell.Value)) = Day(cell.Value)
    End If
    End If
    Next cell

    MaxDate = WorksheetFunction.Max(myarray)

    End Function

    **************************

    I am sure some of the gurus could simplify the logic but for now I hope
    this does the trick.

    let us know if it works
    cheers RES

  41. #41
    Maxi
    Guest

    Re: Max date

    There is a big confusion.

    Let me start over again.......... Now don't look at any previous
    posts.... This is the final and only read this one.

    This is what I have in range A2:G2
    9-May 17-May 1-Jun 15-Jun 13-Jul 14-Jul 18-Jul 13
    13-May 6-Jun 12-Jun 20-Jun 1-Jul 16-Jul 20-Jul 13

    I want to check the first occurring date of each month and then compare
    it with the next occurring first date of the next month and so on and
    then find out the max date.

    Eg.
    First row:
    First date in May 9th, in June 1st, in Jul 13th hence the result should
    be 13
    Second row:
    First date in May 13th, in June 6th, in Jul 1st hence the result should

    be 13

    To make it more simpler:
    Row1:
    There are two dates for May and 9th May is the first date = 9.
    There are two dates for Jun and 1st June is the first date = 1.
    There are three dates for July and 13th July is the first date = 13.
    Therefore the max value is 13 (out of 9 1 and 13) so I1 will contain 13


    Row2:
    There is one date for May and 13th May is the first date = 13.
    There are three dates for Jun and 6th June is the first date = 6.
    There are three dates for July and 1st July is the first date = 1.
    Therefore the max value is 13 (out of 13 6 and 1) so I1 will contain 13


    The answer in I1 and I2 both should come to 13

    Maxi


  42. #42
    Biff
    Guest

    Re: Max date

    Hi!

    Not real elegant but it works without the need for the helper:

    Dates in A2:G2

    Array entered:

    =MAX(DAY(MIN(IF(MONTH(A2:G2)=MONTH(A2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(B2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(C2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(D2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(E2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(F2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(G2),A2:G2))))

    If the months are always a series of three and they're consecutive:

    =MAX(DAY(MIN(IF(MONTH(A2:G2)=MONTH(A2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(A2)+1,A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(A2)+2,A2:G2))))

    If you don't mind hardcoding the months:

    =MAX(DAY(MIN(IF(MONTH(A2:G2)=5,A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=6,A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=7,A2:G2))))

    Couldn't figure out how do do this as a single array statement.

    Biff

    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    > Good logic but as you said without the helper would be an efficient way
    > of doing it. Thanks for your efforts even this formula will work out.
    > Please let me know if you get something better.
    >
    > Maxi
    >




  43. #43
    Maxi
    Guest

    Re: Max date

    You didn't understand my question I guess

    I am looking for a formula in cell I1 and I2

    First of all there are two records.

    Row1:
    There are two dates for May and 9th May is the first date = 9.
    There are two dates for Jun and 1st June is the first date = 1.
    There are three dates for July and 13th July is the first date = 13.
    Therefore the max value is 13 (out of 9 1 and 13) so I1 will contain 13

    Row2:
    There is one date for May and 13th May is the first date = 13.
    There are three dates for Jun and 6th June is the first date = 6.
    There are three dates for July and 1st July is the first date = 1.
    Therefore the max value is 13 (out of 13 6 and 1) so I1 will contain 13

    Maxi


  44. #44
    Biff
    Guest

    Re: Max date

    Hi!

    Don't know anything about VBA but when I try this I get a compile syntax
    error with this section highlighted:

    myarray(Month(cell.Value)) = _
    WorksheetFunction.Min(Day(cell.Value),

    Biff

    <[email protected]> wrote in message
    news:[email protected]...
    >I have also tried to do this as an array and drawn a blank
    > however a UDF if it would help
    >
    > Function MaxDate(myRange As Range) As Integer
    >
    > Dim myarray(1 To 12) As Integer
    > For Each cell In myRange
    > If myarray(Month(cell.Value)) <> 0 Then
    > myarray(Month(cell.Value)) = _
    > WorksheetFunction.Min(Day(cell.Value),
    > myarray(Month(cell.Value)))
    > Else
    > myarray(Month(cell.Value)) = Day(cell.Value)
    > End If
    > Next cell
    >
    > MaxDate = WorksheetFunction.Max(myarray)
    >
    > End Function
    >
    > Feels like brute force though
    >
    > hth RES




  45. #45
    Maxi
    Guest

    Re: Max date

    Sorry. I framed the question incorrectly.

    I want to check the first occurring date of each month and then compare
    it with the next occurring first date of the next month in the array
    and then find out the max date.

    Eg.
    First row:
    First date in May 9th, in June 1st, in Jul 13th hence the result should
    be 13

    Second row:
    First date in May 13th, in June 6th, in Jul 1st hence the result should
    be 13

    Maxi


  46. #46

    Re: Max date

    I have also tried to do this as an array and drawn a blank
    however a UDF if it would help

    Function MaxDate(myRange As Range) As Integer

    Dim myarray(1 To 12) As Integer
    For Each cell In myRange
    If myarray(Month(cell.Value)) <> 0 Then
    myarray(Month(cell.Value)) = _
    WorksheetFunction.Min(Day(cell.Value),
    myarray(Month(cell.Value)))
    Else
    myarray(Month(cell.Value)) = Day(cell.Value)
    End If
    Next cell

    MaxDate = WorksheetFunction.Max(myarray)

    End Function

    Feels like brute force though

    hth RES

  47. #47
    Biff
    Guest

    Re: Max date

    Hi!

    Try this....

    Entered as an array using the key combo of CTRL,SHIFT,ENTER:

    =MAX(DAY(A2:G2))

    Biff

    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    > This is what I have in range A2:G2
    > 9-May 17-May 1-Jun 15-Jun 13-Jul 14-Jul 18-Jul 18
    > 13-May 6-Jun 12-Jun 20-Jun 1-Jul 16-Jul 20-Jul 20
    >
    > I want to see the max date monthwise and then find out the max of all
    > the dates.
    >
    > Eg. In Row 1 max figure for May is 17, June 15, July 18 hence Answer =
    > 18
    > In Row 1 max figure for May is 13, June 20, July 20 hence Answer = 20
    >
    > Maxi
    >




  48. #48
    Maxi
    Guest

    Re: Max date

    Good logic but as you said without the helper would be an efficient way
    of doing it. Thanks for your efforts even this formula will work out.
    Please let me know if you get something better.

    Maxi


  49. #49
    Maxi
    Guest

    Re: Max date

    Works !!!

    Thanx


  50. #50
    Maxi
    Guest

    Re: Max date

    No Biff, the answer is not 20.

    I am looking for an answer that give 13. Look at the corrected
    question. The first question was incorrectly framed.

    Maxi


  51. #51
    Biff
    Guest

    Re: Max date

    Hi!

    I understand what you want. It's not so simple!

    Will the months always be the same? May, June and July?

    Will the dates always be in ascending order?

    Biff

    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    > There is a big confusion.
    >
    > Let me start over again.......... Now don't look at any previous
    > posts.... This is the final and only read this one.
    >
    > This is what I have in range A2:G2
    > 9-May 17-May 1-Jun 15-Jun 13-Jul 14-Jul 18-Jul 13
    > 13-May 6-Jun 12-Jun 20-Jun 1-Jul 16-Jul 20-Jul 13
    >
    > I want to check the first occurring date of each month and then compare
    > it with the next occurring first date of the next month and so on and
    > then find out the max date.
    >
    > Eg.
    > First row:
    > First date in May 9th, in June 1st, in Jul 13th hence the result should
    > be 13
    > Second row:
    > First date in May 13th, in June 6th, in Jul 1st hence the result should
    >
    > be 13
    >
    > To make it more simpler:
    > Row1:
    > There are two dates for May and 9th May is the first date = 9.
    > There are two dates for Jun and 1st June is the first date = 1.
    > There are three dates for July and 13th July is the first date = 13.
    > Therefore the max value is 13 (out of 9 1 and 13) so I1 will contain 13
    >
    >
    > Row2:
    > There is one date for May and 13th May is the first date = 13.
    > There are three dates for Jun and 6th June is the first date = 6.
    > There are three dates for July and 1st July is the first date = 1.
    > Therefore the max value is 13 (out of 13 6 and 1) so I1 will contain 13
    >
    >
    > The answer in I1 and I2 both should come to 13
    >
    > Maxi
    >




  52. #52
    Maxi
    Guest

    Re: Max date

    No, months can be different. There can be a month with 2004 as year and
    same month with 2005. Yes, dates will always be in ascending order.

    If not a formula, even a VBA would do. I am tired of thinking a logic
    on how to get this issue resolved.

    Maxi


  53. #53
    kk
    Guest

    Re: Max date

    Hi!

    I didn't read you first post so I assume your data range is A1:C1

    In I1, type =Max(Day($A2:$G2))

    This is an array formula so you need to confirmed it by Ctrl+Shift+Enter.



    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    You didn't understand my question I guess

    I am looking for a formula in cell I1 and I2

    First of all there are two records.

    Row1:
    There are two dates for May and 9th May is the first date = 9.
    There are two dates for Jun and 1st June is the first date = 1.
    There are three dates for July and 13th July is the first date = 13.
    Therefore the max value is 13 (out of 9 1 and 13) so I1 will contain 13

    Row2:
    There is one date for May and 13th May is the first date = 13.
    There are three dates for Jun and 6th June is the first date = 6.
    There are three dates for July and 1st July is the first date = 1.
    Therefore the max value is 13 (out of 13 6 and 1) so I1 will contain 13

    Maxi



  54. #54
    Biff
    Guest

    Re: Max date

    Hi!

    Here's one way but requires a helper row...

    Dates in A2:G2

    In A3 enter this formula and copy across to G3:

    =IF(SUMPRODUCT(--(MONTH($A2:A2)=MONTH(A2)))>1,"",1)

    Formula for the max day (still an array formula):

    =MAX(DAY(IF(A3:G3=1,A2:G2)))

    You can use this until someone comes up with something better. I'll keep
    trying for something better that doesn't need a helper. I'm close!

    Biff

    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    > No, months can be different. There can be a month with 2004 as year and
    > same month with 2005. Yes, dates will always be in ascending order.
    >
    > If not a formula, even a VBA would do. I am tired of thinking a logic
    > on how to get this issue resolved.
    >
    > Maxi
    >




  55. #55

    Re: Max date

    Maxi
    The array
    > Dim myarray(1 To 12) As Integer

    is equivalent to myarray(jan to dec) and stores a day value in each.
    The reason you were getting incorrect results from the UDF I posted is I
    had not protected against blank cells
    A revised version is posted below.

    The logic is as follows
    Set up a data store for each possible month to hold the day value
    loop through each cell in the range in turn
    if there is a positive value in the cell continue if not skip to the next
    cell
    using the month value of the cell look in the array
    if the entry in the array is not 0 then make it equal to the lowest of
    either the current array value or the day value of the cell
    otherwise put in the day value of the cell
    when all the cells have been checked return the largest value in the array


    ***************************

    Function MaxDate(myRange As Range) As Integer

    Dim myarray(1 To 12) As Integer
    For Each cell In myRange
    If cell.Value > 0 Then
    If myarray(Month(cell.Value)) <> 0 Then
    myarray(Month(cell.Value)) = _
    WorksheetFunction.Min(Day(cell.Value), _
    myarray(Month(cell.Value)))
    Else
    myarray(Month(cell.Value)) = Day(cell.Value)
    End If
    End If
    Next cell

    MaxDate = WorksheetFunction.Max(myarray)

    End Function

    **************************

    I am sure some of the gurus could simplify the logic but for now I hope
    this does the trick.

    let us know if it works
    cheers RES

  56. #56
    kk
    Guest

    Re: Max date

    Hi Maxi,

    Assume your data range A1:C1

    In D1, try this array formula
    =MAX(DAY($A1:$C1))

    Confirm the formula by Ctrl+Shift+Enter

    Does it help?


    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    Sorry. I framed the question incorrectly.

    I want to check the first occurring date of each month and then compare
    it with the next occurring first date of the next month in the array
    and then find out the max date.

    Eg.
    First row:
    First date in May 9th, in June 1st, in Jul 13th hence the result should
    be 13

    Second row:
    First date in May 13th, in June 6th, in Jul 1st hence the result should
    be 13

    Maxi



  57. #57
    kk
    Guest

    Re: Max date

    Hi!

    I didn't read you first post so I assume your data range is A1:C1

    In I1, type =Max(Day($A2:$G2))

    This is an array formula so you need to confirmed it by Ctrl+Shift+Enter.



    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    You didn't understand my question I guess

    I am looking for a formula in cell I1 and I2

    First of all there are two records.

    Row1:
    There are two dates for May and 9th May is the first date = 9.
    There are two dates for Jun and 1st June is the first date = 1.
    There are three dates for July and 13th July is the first date = 13.
    Therefore the max value is 13 (out of 9 1 and 13) so I1 will contain 13

    Row2:
    There is one date for May and 13th May is the first date = 13.
    There are three dates for Jun and 6th June is the first date = 6.
    There are three dates for July and 1st July is the first date = 1.
    Therefore the max value is 13 (out of 13 6 and 1) so I1 will contain 13

    Maxi



  58. #58
    Maxi
    Guest

    Re: Max date

    Biff, I appreciate your efforts and all is working fine but the UDF
    from Robert is an efficient way of doing it.

    As far as speed of processing is concerned, I am not sure if UDF takes
    long time of the array formula.

    Robert, one question for you.

    I didn't understand the line Dim myarray(1 To 12) As Integer

    Why 1 to 12?

    Also the data what I gave was just a sample data. I have around 3160
    rows in my file. When I used Biff's suggestion, everything works fine
    but your UDF does not give me correct results for 366 rows out of 3160.


    In my file I have 3160 rows and 25+ columns. There can be less than 25
    columns in a row or there can be more. Few columns are BLANK but I
    guess your If myarray(Month(cell.Value)) <> 0 Then line will take care
    of it.

    I am just wondering why I am not getting correct result for 366 rows.
    Do I have to make changes in the Dim myarray(1 To 12) As Integer line?

    Maxi


  59. #59
    Biff
    Guest

    Re: Max date

    Hi!

    Here's one way but requires a helper row...

    Dates in A2:G2

    In A3 enter this formula and copy across to G3:

    =IF(SUMPRODUCT(--(MONTH($A2:A2)=MONTH(A2)))>1,"",1)

    Formula for the max day (still an array formula):

    =MAX(DAY(IF(A3:G3=1,A2:G2)))

    You can use this until someone comes up with something better. I'll keep
    trying for something better that doesn't need a helper. I'm close!

    Biff

    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    > No, months can be different. There can be a month with 2004 as year and
    > same month with 2005. Yes, dates will always be in ascending order.
    >
    > If not a formula, even a VBA would do. I am tired of thinking a logic
    > on how to get this issue resolved.
    >
    > Maxi
    >




  60. #60
    Maxi
    Guest

    Re: Max date

    Sorry. I framed the question incorrectly.

    I want to check the first occurring date of each month and then compare
    it with the next occurring first date of the next month in the array
    and then find out the max date.

    Eg.
    First row:
    First date in May 9th, in June 1st, in Jul 13th hence the result should
    be 13

    Second row:
    First date in May 13th, in June 6th, in Jul 1st hence the result should
    be 13

    Maxi


  61. #61
    Biff
    Guest

    Re: Max date

    Hi!

    I understand what you want. It's not so simple!

    Will the months always be the same? May, June and July?

    Will the dates always be in ascending order?

    Biff

    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    > There is a big confusion.
    >
    > Let me start over again.......... Now don't look at any previous
    > posts.... This is the final and only read this one.
    >
    > This is what I have in range A2:G2
    > 9-May 17-May 1-Jun 15-Jun 13-Jul 14-Jul 18-Jul 13
    > 13-May 6-Jun 12-Jun 20-Jun 1-Jul 16-Jul 20-Jul 13
    >
    > I want to check the first occurring date of each month and then compare
    > it with the next occurring first date of the next month and so on and
    > then find out the max date.
    >
    > Eg.
    > First row:
    > First date in May 9th, in June 1st, in Jul 13th hence the result should
    > be 13
    > Second row:
    > First date in May 13th, in June 6th, in Jul 1st hence the result should
    >
    > be 13
    >
    > To make it more simpler:
    > Row1:
    > There are two dates for May and 9th May is the first date = 9.
    > There are two dates for Jun and 1st June is the first date = 1.
    > There are three dates for July and 13th July is the first date = 13.
    > Therefore the max value is 13 (out of 9 1 and 13) so I1 will contain 13
    >
    >
    > Row2:
    > There is one date for May and 13th May is the first date = 13.
    > There are three dates for Jun and 6th June is the first date = 6.
    > There are three dates for July and 1st July is the first date = 1.
    > Therefore the max value is 13 (out of 13 6 and 1) so I1 will contain 13
    >
    >
    > The answer in I1 and I2 both should come to 13
    >
    > Maxi
    >




  62. #62

    Re: Max date

    Biff
    The problem is due to the wonderful line wrapping that happens with a post

    > myarray(Month(cell.Value)) = _
    > WorksheetFunction.Min(Day(cell.Value),
    > myarray(Month(cell.Value)))


    is all one line of code.
    The _ tells VBA to complie the next line as part of the current.
    Try it as

    myarray(Month(cell.Value)) = _
    WorksheetFunction.Min(Day(cell.Value), _
    myarray(Month(cell.Value)))

    Hopefully the newsgroup engines will not introduce any unforeseen wraps

  63. #63
    Biff
    Guest

    Re: Max date

    Hi!

    Try this....

    Entered as an array using the key combo of CTRL,SHIFT,ENTER:

    =MAX(DAY(A2:G2))

    Biff

    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    > This is what I have in range A2:G2
    > 9-May 17-May 1-Jun 15-Jun 13-Jul 14-Jul 18-Jul 18
    > 13-May 6-Jun 12-Jun 20-Jun 1-Jul 16-Jul 20-Jul 20
    >
    > I want to see the max date monthwise and then find out the max of all
    > the dates.
    >
    > Eg. In Row 1 max figure for May is 17, June 15, July 18 hence Answer =
    > 18
    > In Row 1 max figure for May is 13, June 20, July 20 hence Answer = 20
    >
    > Maxi
    >




  64. #64
    Maxi
    Guest

    Re: Max date

    No, months can be different. There can be a month with 2004 as year and
    same month with 2005. Yes, dates will always be in ascending order.

    If not a formula, even a VBA would do. I am tired of thinking a logic
    on how to get this issue resolved.

    Maxi


  65. #65
    Biff
    Guest

    Re: Max date

    Hi!

    Not real elegant but it works without the need for the helper:

    Dates in A2:G2

    Array entered:

    =MAX(DAY(MIN(IF(MONTH(A2:G2)=MONTH(A2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(B2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(C2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(D2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(E2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(F2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(G2),A2:G2))))

    If the months are always a series of three and they're consecutive:

    =MAX(DAY(MIN(IF(MONTH(A2:G2)=MONTH(A2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(A2)+1,A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(A2)+2,A2:G2))))

    If you don't mind hardcoding the months:

    =MAX(DAY(MIN(IF(MONTH(A2:G2)=5,A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=6,A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=7,A2:G2))))

    Couldn't figure out how do do this as a single array statement.

    Biff

    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    > Good logic but as you said without the helper would be an efficient way
    > of doing it. Thanks for your efforts even this formula will work out.
    > Please let me know if you get something better.
    >
    > Maxi
    >




  66. #66
    Maxi
    Guest

    Re: Max date

    Works !!!

    Thanx


  67. #67
    Maxi
    Guest

    Re: Max date

    You didn't understand my question I guess

    I am looking for a formula in cell I1 and I2

    First of all there are two records.

    Row1:
    There are two dates for May and 9th May is the first date = 9.
    There are two dates for Jun and 1st June is the first date = 1.
    There are three dates for July and 13th July is the first date = 13.
    Therefore the max value is 13 (out of 9 1 and 13) so I1 will contain 13

    Row2:
    There is one date for May and 13th May is the first date = 13.
    There are three dates for Jun and 6th June is the first date = 6.
    There are three dates for July and 1st July is the first date = 1.
    Therefore the max value is 13 (out of 13 6 and 1) so I1 will contain 13

    Maxi


  68. #68
    Biff
    Guest

    Re: Max date

    Hi!

    Don't know anything about VBA but when I try this I get a compile syntax
    error with this section highlighted:

    myarray(Month(cell.Value)) = _
    WorksheetFunction.Min(Day(cell.Value),

    Biff

    <[email protected]> wrote in message
    news:[email protected]...
    >I have also tried to do this as an array and drawn a blank
    > however a UDF if it would help
    >
    > Function MaxDate(myRange As Range) As Integer
    >
    > Dim myarray(1 To 12) As Integer
    > For Each cell In myRange
    > If myarray(Month(cell.Value)) <> 0 Then
    > myarray(Month(cell.Value)) = _
    > WorksheetFunction.Min(Day(cell.Value),
    > myarray(Month(cell.Value)))
    > Else
    > myarray(Month(cell.Value)) = Day(cell.Value)
    > End If
    > Next cell
    >
    > MaxDate = WorksheetFunction.Max(myarray)
    >
    > End Function
    >
    > Feels like brute force though
    >
    > hth RES




  69. #69
    Maxi
    Guest

    Re: Max date

    Good logic but as you said without the helper would be an efficient way
    of doing it. Thanks for your efforts even this formula will work out.
    Please let me know if you get something better.

    Maxi


  70. #70

    Re: Max date

    I have also tried to do this as an array and drawn a blank
    however a UDF if it would help

    Function MaxDate(myRange As Range) As Integer

    Dim myarray(1 To 12) As Integer
    For Each cell In myRange
    If myarray(Month(cell.Value)) <> 0 Then
    myarray(Month(cell.Value)) = _
    WorksheetFunction.Min(Day(cell.Value),
    myarray(Month(cell.Value)))
    Else
    myarray(Month(cell.Value)) = Day(cell.Value)
    End If
    Next cell

    MaxDate = WorksheetFunction.Max(myarray)

    End Function

    Feels like brute force though

    hth RES

  71. #71
    Maxi
    Guest

    Re: Max date

    There is a big confusion.

    Let me start over again.......... Now don't look at any previous
    posts.... This is the final and only read this one.

    This is what I have in range A2:G2
    9-May 17-May 1-Jun 15-Jun 13-Jul 14-Jul 18-Jul 13
    13-May 6-Jun 12-Jun 20-Jun 1-Jul 16-Jul 20-Jul 13

    I want to check the first occurring date of each month and then compare
    it with the next occurring first date of the next month and so on and
    then find out the max date.

    Eg.
    First row:
    First date in May 9th, in June 1st, in Jul 13th hence the result should
    be 13
    Second row:
    First date in May 13th, in June 6th, in Jul 1st hence the result should

    be 13

    To make it more simpler:
    Row1:
    There are two dates for May and 9th May is the first date = 9.
    There are two dates for Jun and 1st June is the first date = 1.
    There are three dates for July and 13th July is the first date = 13.
    Therefore the max value is 13 (out of 9 1 and 13) so I1 will contain 13


    Row2:
    There is one date for May and 13th May is the first date = 13.
    There are three dates for Jun and 6th June is the first date = 6.
    There are three dates for July and 1st July is the first date = 1.
    Therefore the max value is 13 (out of 13 6 and 1) so I1 will contain 13


    The answer in I1 and I2 both should come to 13

    Maxi


  72. #72
    Maxi
    Guest

    Re: Max date

    No Biff, the answer is not 20.

    I am looking for an answer that give 13. Look at the corrected
    question. The first question was incorrectly framed.

    Maxi


  73. #73

    Re: Max date

    Maxi
    The array
    > Dim myarray(1 To 12) As Integer

    is equivalent to myarray(jan to dec) and stores a day value in each.
    The reason you were getting incorrect results from the UDF I posted is I
    had not protected against blank cells
    A revised version is posted below.

    The logic is as follows
    Set up a data store for each possible month to hold the day value
    loop through each cell in the range in turn
    if there is a positive value in the cell continue if not skip to the next
    cell
    using the month value of the cell look in the array
    if the entry in the array is not 0 then make it equal to the lowest of
    either the current array value or the day value of the cell
    otherwise put in the day value of the cell
    when all the cells have been checked return the largest value in the array


    ***************************

    Function MaxDate(myRange As Range) As Integer

    Dim myarray(1 To 12) As Integer
    For Each cell In myRange
    If cell.Value > 0 Then
    If myarray(Month(cell.Value)) <> 0 Then
    myarray(Month(cell.Value)) = _
    WorksheetFunction.Min(Day(cell.Value), _
    myarray(Month(cell.Value)))
    Else
    myarray(Month(cell.Value)) = Day(cell.Value)
    End If
    End If
    Next cell

    MaxDate = WorksheetFunction.Max(myarray)

    End Function

    **************************

    I am sure some of the gurus could simplify the logic but for now I hope
    this does the trick.

    let us know if it works
    cheers RES

  74. #74
    Maxi
    Guest

    Re: Max date

    Works !!!

    Thanx


  75. #75
    kk
    Guest

    Re: Max date

    Hi!

    I didn't read you first post so I assume your data range is A1:C1

    In I1, type =Max(Day($A2:$G2))

    This is an array formula so you need to confirmed it by Ctrl+Shift+Enter.



    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    You didn't understand my question I guess

    I am looking for a formula in cell I1 and I2

    First of all there are two records.

    Row1:
    There are two dates for May and 9th May is the first date = 9.
    There are two dates for Jun and 1st June is the first date = 1.
    There are three dates for July and 13th July is the first date = 13.
    Therefore the max value is 13 (out of 9 1 and 13) so I1 will contain 13

    Row2:
    There is one date for May and 13th May is the first date = 13.
    There are three dates for Jun and 6th June is the first date = 6.
    There are three dates for July and 1st July is the first date = 1.
    Therefore the max value is 13 (out of 13 6 and 1) so I1 will contain 13

    Maxi



  76. #76
    Maxi
    Guest

    Re: Max date

    Sorry. I framed the question incorrectly.

    I want to check the first occurring date of each month and then compare
    it with the next occurring first date of the next month in the array
    and then find out the max date.

    Eg.
    First row:
    First date in May 9th, in June 1st, in Jul 13th hence the result should
    be 13

    Second row:
    First date in May 13th, in June 6th, in Jul 1st hence the result should
    be 13

    Maxi


  77. #77
    Maxi
    Guest

    Re: Max date

    There is a big confusion.

    Let me start over again.......... Now don't look at any previous
    posts.... This is the final and only read this one.

    This is what I have in range A2:G2
    9-May 17-May 1-Jun 15-Jun 13-Jul 14-Jul 18-Jul 13
    13-May 6-Jun 12-Jun 20-Jun 1-Jul 16-Jul 20-Jul 13

    I want to check the first occurring date of each month and then compare
    it with the next occurring first date of the next month and so on and
    then find out the max date.

    Eg.
    First row:
    First date in May 9th, in June 1st, in Jul 13th hence the result should
    be 13
    Second row:
    First date in May 13th, in June 6th, in Jul 1st hence the result should

    be 13

    To make it more simpler:
    Row1:
    There are two dates for May and 9th May is the first date = 9.
    There are two dates for Jun and 1st June is the first date = 1.
    There are three dates for July and 13th July is the first date = 13.
    Therefore the max value is 13 (out of 9 1 and 13) so I1 will contain 13


    Row2:
    There is one date for May and 13th May is the first date = 13.
    There are three dates for Jun and 6th June is the first date = 6.
    There are three dates for July and 1st July is the first date = 1.
    Therefore the max value is 13 (out of 13 6 and 1) so I1 will contain 13


    The answer in I1 and I2 both should come to 13

    Maxi


  78. #78
    Maxi
    Guest

    Max date

    This is what I have in range A2:G2
    9-May 17-May 1-Jun 15-Jun 13-Jul 14-Jul 18-Jul 18
    13-May 6-Jun 12-Jun 20-Jun 1-Jul 16-Jul 20-Jul 20

    I want to see the max date monthwise and then find out the max of all
    the dates.

    Eg. In Row 1 max figure for May is 17, June 15, July 18 hence Answer =
    18
    In Row 1 max figure for May is 13, June 20, July 20 hence Answer = 20

    Maxi


  79. #79
    kk
    Guest

    Re: Max date

    Hi Maxi,

    Assume your data range A1:C1

    In D1, try this array formula
    =MAX(DAY($A1:$C1))

    Confirm the formula by Ctrl+Shift+Enter

    Does it help?


    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    Sorry. I framed the question incorrectly.

    I want to check the first occurring date of each month and then compare
    it with the next occurring first date of the next month in the array
    and then find out the max date.

    Eg.
    First row:
    First date in May 9th, in June 1st, in Jul 13th hence the result should
    be 13

    Second row:
    First date in May 13th, in June 6th, in Jul 1st hence the result should
    be 13

    Maxi



  80. #80
    Maxi
    Guest

    Re: Max date

    Good logic but as you said without the helper would be an efficient way
    of doing it. Thanks for your efforts even this formula will work out.
    Please let me know if you get something better.

    Maxi


  81. #81
    Maxi
    Guest

    Re: Max date

    Biff, I appreciate your efforts and all is working fine but the UDF
    from Robert is an efficient way of doing it.

    As far as speed of processing is concerned, I am not sure if UDF takes
    long time of the array formula.

    Robert, one question for you.

    I didn't understand the line Dim myarray(1 To 12) As Integer

    Why 1 to 12?

    Also the data what I gave was just a sample data. I have around 3160
    rows in my file. When I used Biff's suggestion, everything works fine
    but your UDF does not give me correct results for 366 rows out of 3160.


    In my file I have 3160 rows and 25+ columns. There can be less than 25
    columns in a row or there can be more. Few columns are BLANK but I
    guess your If myarray(Month(cell.Value)) <> 0 Then line will take care
    of it.

    I am just wondering why I am not getting correct result for 366 rows.
    Do I have to make changes in the Dim myarray(1 To 12) As Integer line?

    Maxi


  82. #82

    Re: Max date

    Biff
    The problem is due to the wonderful line wrapping that happens with a post

    > myarray(Month(cell.Value)) = _
    > WorksheetFunction.Min(Day(cell.Value),
    > myarray(Month(cell.Value)))


    is all one line of code.
    The _ tells VBA to complie the next line as part of the current.
    Try it as

    myarray(Month(cell.Value)) = _
    WorksheetFunction.Min(Day(cell.Value), _
    myarray(Month(cell.Value)))

    Hopefully the newsgroup engines will not introduce any unforeseen wraps

  83. #83
    Biff
    Guest

    Re: Max date

    Hi!

    I understand what you want. It's not so simple!

    Will the months always be the same? May, June and July?

    Will the dates always be in ascending order?

    Biff

    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    > There is a big confusion.
    >
    > Let me start over again.......... Now don't look at any previous
    > posts.... This is the final and only read this one.
    >
    > This is what I have in range A2:G2
    > 9-May 17-May 1-Jun 15-Jun 13-Jul 14-Jul 18-Jul 13
    > 13-May 6-Jun 12-Jun 20-Jun 1-Jul 16-Jul 20-Jul 13
    >
    > I want to check the first occurring date of each month and then compare
    > it with the next occurring first date of the next month and so on and
    > then find out the max date.
    >
    > Eg.
    > First row:
    > First date in May 9th, in June 1st, in Jul 13th hence the result should
    > be 13
    > Second row:
    > First date in May 13th, in June 6th, in Jul 1st hence the result should
    >
    > be 13
    >
    > To make it more simpler:
    > Row1:
    > There are two dates for May and 9th May is the first date = 9.
    > There are two dates for Jun and 1st June is the first date = 1.
    > There are three dates for July and 13th July is the first date = 13.
    > Therefore the max value is 13 (out of 9 1 and 13) so I1 will contain 13
    >
    >
    > Row2:
    > There is one date for May and 13th May is the first date = 13.
    > There are three dates for Jun and 6th June is the first date = 6.
    > There are three dates for July and 1st July is the first date = 1.
    > Therefore the max value is 13 (out of 13 6 and 1) so I1 will contain 13
    >
    >
    > The answer in I1 and I2 both should come to 13
    >
    > Maxi
    >




  84. #84
    Maxi
    Guest

    Re: Max date

    You didn't understand my question I guess

    I am looking for a formula in cell I1 and I2

    First of all there are two records.

    Row1:
    There are two dates for May and 9th May is the first date = 9.
    There are two dates for Jun and 1st June is the first date = 1.
    There are three dates for July and 13th July is the first date = 13.
    Therefore the max value is 13 (out of 9 1 and 13) so I1 will contain 13

    Row2:
    There is one date for May and 13th May is the first date = 13.
    There are three dates for Jun and 6th June is the first date = 6.
    There are three dates for July and 1st July is the first date = 1.
    Therefore the max value is 13 (out of 13 6 and 1) so I1 will contain 13

    Maxi


  85. #85
    Biff
    Guest

    Re: Max date

    Hi!

    Not real elegant but it works without the need for the helper:

    Dates in A2:G2

    Array entered:

    =MAX(DAY(MIN(IF(MONTH(A2:G2)=MONTH(A2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(B2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(C2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(D2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(E2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(F2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(G2),A2:G2))))

    If the months are always a series of three and they're consecutive:

    =MAX(DAY(MIN(IF(MONTH(A2:G2)=MONTH(A2),A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(A2)+1,A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=MONTH(A2)+2,A2:G2))))

    If you don't mind hardcoding the months:

    =MAX(DAY(MIN(IF(MONTH(A2:G2)=5,A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=6,A2:G2))),DAY(MIN(IF(MONTH(A2:G2)=7,A2:G2))))

    Couldn't figure out how do do this as a single array statement.

    Biff

    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    > Good logic but as you said without the helper would be an efficient way
    > of doing it. Thanks for your efforts even this formula will work out.
    > Please let me know if you get something better.
    >
    > Maxi
    >




  86. #86
    Maxi
    Guest

    Re: Max date

    No, months can be different. There can be a month with 2004 as year and
    same month with 2005. Yes, dates will always be in ascending order.

    If not a formula, even a VBA would do. I am tired of thinking a logic
    on how to get this issue resolved.

    Maxi


  87. #87
    Biff
    Guest

    Re: Max date

    Hi!

    Don't know anything about VBA but when I try this I get a compile syntax
    error with this section highlighted:

    myarray(Month(cell.Value)) = _
    WorksheetFunction.Min(Day(cell.Value),

    Biff

    <[email protected]> wrote in message
    news:[email protected]...
    >I have also tried to do this as an array and drawn a blank
    > however a UDF if it would help
    >
    > Function MaxDate(myRange As Range) As Integer
    >
    > Dim myarray(1 To 12) As Integer
    > For Each cell In myRange
    > If myarray(Month(cell.Value)) <> 0 Then
    > myarray(Month(cell.Value)) = _
    > WorksheetFunction.Min(Day(cell.Value),
    > myarray(Month(cell.Value)))
    > Else
    > myarray(Month(cell.Value)) = Day(cell.Value)
    > End If
    > Next cell
    >
    > MaxDate = WorksheetFunction.Max(myarray)
    >
    > End Function
    >
    > Feels like brute force though
    >
    > hth RES




  88. #88

    Re: Max date

    I have also tried to do this as an array and drawn a blank
    however a UDF if it would help

    Function MaxDate(myRange As Range) As Integer

    Dim myarray(1 To 12) As Integer
    For Each cell In myRange
    If myarray(Month(cell.Value)) <> 0 Then
    myarray(Month(cell.Value)) = _
    WorksheetFunction.Min(Day(cell.Value),
    myarray(Month(cell.Value)))
    Else
    myarray(Month(cell.Value)) = Day(cell.Value)
    End If
    Next cell

    MaxDate = WorksheetFunction.Max(myarray)

    End Function

    Feels like brute force though

    hth RES

  89. #89
    Maxi
    Guest

    Re: Max date

    No Biff, the answer is not 20.

    I am looking for an answer that give 13. Look at the corrected
    question. The first question was incorrectly framed.

    Maxi


  90. #90
    Biff
    Guest

    Re: Max date

    Hi!

    Here's one way but requires a helper row...

    Dates in A2:G2

    In A3 enter this formula and copy across to G3:

    =IF(SUMPRODUCT(--(MONTH($A2:A2)=MONTH(A2)))>1,"",1)

    Formula for the max day (still an array formula):

    =MAX(DAY(IF(A3:G3=1,A2:G2)))

    You can use this until someone comes up with something better. I'll keep
    trying for something better that doesn't need a helper. I'm close!

    Biff

    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    > No, months can be different. There can be a month with 2004 as year and
    > same month with 2005. Yes, dates will always be in ascending order.
    >
    > If not a formula, even a VBA would do. I am tired of thinking a logic
    > on how to get this issue resolved.
    >
    > Maxi
    >




  91. #91
    Biff
    Guest

    Re: Max date

    Hi!

    Try this....

    Entered as an array using the key combo of CTRL,SHIFT,ENTER:

    =MAX(DAY(A2:G2))

    Biff

    "Maxi" <[email protected]> wrote in message
    news:[email protected]...
    > This is what I have in range A2:G2
    > 9-May 17-May 1-Jun 15-Jun 13-Jul 14-Jul 18-Jul 18
    > 13-May 6-Jun 12-Jun 20-Jun 1-Jul 16-Jul 20-Jul 20
    >
    > I want to see the max date monthwise and then find out the max of all
    > the dates.
    >
    > Eg. In Row 1 max figure for May is 17, June 15, July 18 hence Answer =
    > 18
    > In Row 1 max figure for May is 13, June 20, July 20 hence Answer = 20
    >
    > Maxi
    >




Closed 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