+ Reply to Thread
Results 1 to 23 of 23

identify earliest & latest date groups in table

Hybrid View

  1. #1
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: identify earliest & latest date groups in table

    Sorry, what I meant was, are any of the Data cells That should have Text Numbers or Dates Blank or any of the Data cells that should contain Dates, Blank.
    Example :- Your data is in Columns "L to O", if say there are 100 rows in those columns with data if any cell within this range is blank or has not got a date, you could get that error.
    If there are blanks and that is how your data would normally be presented to you, then I can perhaps alter the code to take account of that, but I was trying to understand where the error came from.
    Mick

  2. #2
    Forum Contributor
    Join Date
    01-23-2010
    Location
    Suffolk, England
    MS-Off Ver
    Office 365
    Posts
    271

    Re: identify earliest & latest date groups in table

    Sorry I misunderstood.

    The data in columns L & M is alphanumeric for grouping. The data in N & O is date format, can be over 1000 rows but there are occasional blanks.

    Thanks

    Louise

  3. #3
    Forum Contributor
    Join Date
    01-23-2010
    Location
    Suffolk, England
    MS-Off Ver
    Office 365
    Posts
    271

    Re: identify earliest & latest date groups in table

    I forgot to say - also row 1 contains text headings.

    Louise

  4. #4
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: identify earliest & latest date groups in table

    Try this:-
    Sub MG18Jul13
    Dim Rng     As Range
    Dim Dn      As Range
    Dim Q       As Variant
    Dim Twn     As String
    Dim Dt1 As Date
    Dim Dt2 As Date
    Set Rng = Range(Range("L2"), Range("L" & Rows.Count).End(xlUp))
        With CreateObject("scripting.dictionary")
           .CompareMode = vbTextCompare
    For Each Dn In Rng
        If Application.CountA(Dn.Resize(, 4)) = 4 Then
        Twn = Dn & Dn.Offset(, 1)
            Dt1 = Format(Dn(, 3), "dd/mm/yyyy")
            Dt2 = Format(Dn(, 4), "dd/mm/yyyy")
            If Not .Exists(Twn) Then
                .Add Twn, Array(Dn, Dn(, 2), Dt1, Dt2)
            Else
                Q = .Item(Twn)
                If Dt1 < DateValue(Q(2)) Then Q(2) = Dt1
                If Dt1 > DateValue(Q(3)) Then Q(3) = Dt2
                .Item(Twn) = Q
            End If
      End If
    Next
     Sheets("sheet2").Range("A1").Resize(.Count, 4) = Application.Index(.items, Evaluate("row(" & 1 & ":" & .Count & " )"), Array(1, 2, 3, 4))
    End With
    End Sub
    Regards Mick
    Last edited by MickG; 07-18-2011 at 11:44 AM.

  5. #5
    Forum Contributor
    Join Date
    01-23-2010
    Location
    Suffolk, England
    MS-Off Ver
    Office 365
    Posts
    271

    Re: identify earliest & latest date groups in table

    Hi Mick,

    I get a Compile error - expected End With

    This sounds simple but not sure where to put it?

    Thanks

    Louise

  6. #6
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: identify earliest & latest date groups in table

    Sorry , Bad Copying.
    I've altered the code above
    "End With" is right at the bottom just above "End Sub"
    Mick

  7. #7
    Forum Contributor
    Join Date
    01-23-2010
    Location
    Suffolk, England
    MS-Off Ver
    Office 365
    Posts
    271

    Re: identify earliest & latest date groups in table

    Run time error 13 - type mismatch

    the debugger is highlighting this line;

    Sheets("Group Dates").Range("A1").Resize(.Count, 4) = Application.Index(.items, Evaluate("row(" & 1 & ":" & .Count & " )"), Array(1, 2, 3, 4))
    I get the feeling we're nearly there

    Thanks for your patience

    Steve

+ 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