Results 1 to 5 of 5

Sorting by Date Macro

Threaded View

  1. #1
    Registered User
    Join Date
    12-26-2015
    Location
    Las Vegas
    MS-Off Ver
    2013
    Posts
    56

    Sorting by Date Macro

    Hello Gurus,

    I cannot figure out why this doesn't work for data with 2017 dates in it... it works for 2016 just fine... any help would be AMAZING!

    Sub PullNumbers()
    
    Dim DateARR As Variant, SummaryARR As Variant, ws As Worksheet
    Dim LR As Long, d As Long, s As Long, CNT As Long
    
    For Each ws In ActiveWorkbook.Worksheets
        With ws
            .Range("O:P").Clear
            LR = .Range("G" & .Rows.Count).End(xlUp).Row
            ReDim DateARR(1 To LR, 1 To 1)
            ReDim SummaryARR(1 To LR, 1 To 2)
            DateARR = .Range("G1:G" & LR)
            SummaryARR(1, 1) = "Date"
            SummaryARR(1, 2) = "Count"
            s = 2
            SummaryARR(2, 1) = CDate(Left(DateARR(2, 1), 10))
            For d = 2 To LR
                If CDate(Left(DateARR(d, 1), 10)) = SummaryARR(s, 1) Then
                    SummaryARR(s, 2) = SummaryARR(s, 2) + 1
            
                Else
                    s = s + 1
                    If Month(CDate(Left(DateARR(d, 1), 10))) <> Month(SummaryARR(s - 1, 1)) Then
                        SummaryARR(s, 1) = "Total:"
                        SummaryARR(s, 2) = CNT
                        CNT = 0
                        s = s + 1
                    End If
                    SummaryARR(s, 1) = CDate(Left(DateARR(d, 1), 10))
                    SummaryARR(s, 2) = SummaryARR(s, 2) + 1
                End If
                CNT = CNT + 1
                If d = LR Then
                    s = s + 1
                    SummaryARR(s, 1) = "Total:"
                    SummaryARR(s, 2) = CNT
                    CNT = 0
                End If
            Next d
            .Range("O1:P" & LR) = SummaryARR
            LR = .Range("O" & .Rows.Count).End(xlUp).Row
            With .Range("O1:P" & LR)
                .EntireColumn.AutoFit
                .FormatConditions.Add Type:=xlExpression, Formula1:="=$O1=""Total:"""
                .FormatConditions(.FormatConditions.Count).SetFirstPriority
                .FormatConditions(1).Font.Bold = True
                With .FormatConditions(1).Interior
                    .PatternColorIndex = xlAutomatic
                    .Color = 5296274
                    .TintAndShade = 0
                End With
                .FormatConditions(1).StopIfTrue = False
            End With
            .Range("O1:P1").Font.Bold = True
        End With
    Next ws
    
    End Sub
    Last edited by InkyDrinky; 01-03-2017 at 11:33 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro for date sorting
    By Patcheen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-06-2016, 02:44 PM
  2. Sorting by date for an irregular date format
    By needhalp in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-14-2014, 04:20 PM
  3. Converting Text to Date & Sorting on Date
    By andresndor in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 03-10-2014, 04:48 PM
  4. Sorting by Date--Need help when sorting by 2-digit year
    By Farris_TN in forum Excel General
    Replies: 3
    Last Post: 06-20-2013, 11:20 AM
  5. Sorting Data by Date in Macro
    By ldaxford in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-10-2010, 12:36 PM
  6. Date Sorting with key field as date and month only.
    By kvbalakumar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-13-2009, 03:02 AM
  7. 3 columns; date and two data, problem is sorting and calculating with respect to date
    By phosphorescence in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-29-2008, 04:21 PM

Tags for this Thread

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