+ Reply to Thread
Results 1 to 5 of 5

Chronological Sorting Problem

Hybrid View

  1. #1
    Registered User
    Join Date
    01-08-2014
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    3

    Chronological Sorting Problem

    I need to sort a column of data by date in Excel. The challenge is some rows show a single month (e.g. April 2013), and other show two months separated by a slash (May/June 2013). There is not much logic to which rows have the back-to-back months, so I can't do a simple find and replace. Can I use a formula or some other Excel trick to get all of the back-to-back months to fall into chronological order.

    Essentially, I need a function that removes anything between a / and a number (the year).

    The other challenge I am finding is that, when I create a function that gets close to the solution, the function column can't be sorted chronologically.

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Chronological Sorting Problem

    Can you upload an example workbook with an example of your data?

    For what it's worth you could turn May/June 2013 into May 2013 using something like:
    =LEFT(A1,FIND("/",A1,1)-1)&" "&RIGHT(A1,4)

    perhaps you would then want to return the datevalue:
    =datevalue(LEFT(A1,FIND("/",A1,1)-1)&" "&RIGHT(A1,4))

    but it would depend on the format of the rest of your data..

  3. #3
    Registered User
    Join Date
    01-08-2014
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Chronological Sorting Problem

    Thanks for the response. My challenge is that there is no consistency on the double months, and I need to run this report every month. So -4 solution would work for May, but no other months. Here is the file:

    monthlydata.xlsx

    Thanks again for your help!

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Chronological Sorting Problem

    ok so some of your examples make this more difficult with having other words and things in the phrases. I think the best way might be a UDF along the lines of:
    Public Function Get_month(str)
    Dim count, count1
    str = Split(Replace(str, "/", " "), " ")
    count = 0
    Do Until str(count) = "January" Or str(count) = "February" Or str(count) = "March" _
        Or str(count) = "April" Or str(count) = "May" Or str(count) = "June" _
        Or str(count) = "July" Or str(count) = "August" Or str(count) = "October" _
        Or str(count) = "October" Or str(count) = "November" Or str(count) = "December"
        count = count + 1
    Loop
    For count1 = LBound(str) To UBound(str)
        If Len(str(count1)) = 4 And Left(str(count1), 2) = "20" Then
            Get_month = CDate("01 " & str(count) & " " & str(count1))
            Exit Function
        End If
    Next count1
    End Function
    Press Alt+F11 to open the vba editor, click insert-> module and then copy that code in.

    Then on your worksheet, in H8 put:
    =IF(ISNUMBER(A8),A8,Get_month(A8))
    and copy down, you can then sort by this column.

  5. #5
    Registered User
    Join Date
    01-08-2014
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Chronological Sorting Problem

    Thanks! This works perfectly.

+ 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. Formula for finding the Chronological age of a person.
    By Wskip49 in forum Access Tables & Databases
    Replies: 1
    Last Post: 11-28-2012, 07:32 PM
  2. obtain chronological order without sorting
    By Diamant in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-21-2012, 12:18 AM
  3. [SOLVED] Re-Arranging Numbers to be in Chronological Order
    By rlpowers in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-27-2012, 10:21 PM
  4. Chronological Time in Column
    By Landsurveyor in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-02-2009, 03:39 PM
  5. Chronological sorting
    By isa in forum Excel General
    Replies: 10
    Last Post: 02-26-2007, 08:46 AM

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