+ Reply to Thread
Results 1 to 30 of 30

Help to Sort Data Chronologically

  1. #1
    Registered User
    Join Date
    10-09-2018
    Location
    Malaysia
    MS-Off Ver
    2016
    Posts
    15

    Help to Sort Data Chronologically

    I have a data set with years as follows :
    2003, 2012, 2014, 2017 (Unsorted Excel)
    I want to arrange the years chronically from 2000, 2001, 2002, 2003, ...2017 (Sorted Excel).
    The manual way will take a lot of time, is there any other way to do it?
    Even if some of the years does not have data, I still want to maintain the chronological order
    with blank spaces for its data. Kindly assist.


    Unsorted Excel.jpgSorted Excel.jpg
    Attached Images Attached Images
    Last edited by skypumpkin; 10-09-2018 at 11:04 AM.

  2. #2
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Help to Sort Data Chronologically

    Hello and welcome to the forum.

    Highlight all of your data > Data > Sort > Sort by year Oldest to Newest > OK

  3. #3
    Registered User
    Join Date
    10-09-2018
    Location
    Malaysia
    MS-Off Ver
    2016
    Posts
    15

    Re: Help to Sort Data Chronologically

    Hello, please refer to the first two images attached. I require it to be arranged according to the code 22, 30, 32, 34... in separate identical tables as shown in the second image. Is there any VBA code to sort it like that?

  4. #4
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Help to Sort Data Chronologically

    I recommend uploading a small representative sample of your data (in the form of an Excel workbook, not screenshots) along with the desired results (which you can enter manually) based on that data.

    To upload an Excel workbook, follow these steps:
    1) Click on "Go Advanced"
    2) Click on "Manage Attachments"
    3) Click on "Choose File"
    4) Choose your file and click on "Open"
    5) Click on "Upload"
    6) Click on "Close this window"

    While I can't help with VBA, I am confident that I can offer a solution that does not require it.

  5. #5
    Registered User
    Join Date
    10-09-2018
    Location
    Malaysia
    MS-Off Ver
    2016
    Posts
    15

    Re: Help to Sort Data Chronologically

    I have attached the file.
    Attached Files Attached Files

  6. #6
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Help to Sort Data Chronologically

    How about a Pivot Table?

    All that you have to do is change the filter to the Commodity Code that you want to see.

    See attachment.

    To create this, highlight your data > Insert > Pivot Table > Drag Year under ROWS, Value under VALUES, and Commodity Code under FILTERS

    To display all years, right-click on any of the years in the Pivot Table > Field Settings > Layout & Print > Check "Show items with no data" > OK

    You can hide the Grand Total row if you would like as well.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    10-09-2018
    Location
    Malaysia
    MS-Off Ver
    2016
    Posts
    15

    Re: Help to Sort Data Chronologically

    Is it possible to do it automatically for other codes? Because there are like 40 other codes, and 28 more data sets

  8. #8
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Help to Sort Data Chronologically

    All that you have to do is change the filter to the commodity code that you want.

    If you don't want to have to do that, here is a quick way to get all of the values for all of the years for each Commodity Code.

    First, list the years in E2:E18 and the Commodity Codes in F1:AU1. Then, you can use this in F2:
    =IFERROR(1/(1/SUMIFS($C:$C,$A:$A,$E2,$B:$B,F$1)),"")
    Drag the formula to the right and down.

    See attachment.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    10-09-2018
    Location
    Malaysia
    MS-Off Ver
    2016
    Posts
    15

    Re: Help to Sort Data Chronologically

    That's great, But, please see the Sheet 2 in the file, I want it to be arranged vertically as shown for all the Commodity Codes. Will that be possible? Kind of like transpose what you have done.

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Help to Sort Data Chronologically

    Hi skypumpkin
    How come it is in your output for Code 22 you have years 2000 to 2017 yet the output for Code 30 you have years 1990 to 2017?
    How do you determine what years to include?
    Do you need years without values?
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  11. #11
    Registered User
    Join Date
    10-09-2018
    Location
    Malaysia
    MS-Off Ver
    2016
    Posts
    15

    Re: Help to Sort Data Chronologically

    Hello jaslake, sorry for the confusion. I have uploaded the corrected Sheet 2.
    All tables must have years 2000 till 2017. The Pivot table is a great help.
    Please advise how to automate the data accordingly in vertical manner.
    Attached Files Attached Files

  12. #12
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Help to Sort Data Chronologically

    Hi skypumpkin
    I'll look at this tomorrow...late here...should not be terribly difficult with VBA...

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Help to Sort Data Chronologically

    Try
    Please Login or Register  to view this content.
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    10-09-2018
    Location
    Malaysia
    MS-Off Ver
    2016
    Posts
    15

    Re: Help to Sort Data Chronologically

    Thank you so much! I tried using Show Report Filter Pages from Pivot Table.
    However, it does not include Commodity Code inside the table as I want. It's outside with the filter tab.
    And also that the tables appear in separate worksheets, when I want them to be consolidated into single worksheet.
    Hope to hear from you soon! Thanks!
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    10-09-2018
    Location
    Malaysia
    MS-Off Ver
    2016
    Posts
    15

    Re: Help to Sort Data Chronologically

    Hello jindon, I'll try to code right away!

  16. #16
    Registered User
    Join Date
    10-09-2018
    Location
    Malaysia
    MS-Off Ver
    2016
    Posts
    15

    Re: Help to Sort Data Chronologically

    vba bug.jpg

    Hello jindon, I can't run the code.
    A bug appears as shown in the photo.

  17. #17
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Help to Sort Data Chronologically

    Does that appear when you run the code with the file I attached?

  18. #18
    Registered User
    Join Date
    10-09-2018
    Location
    Malaysia
    MS-Off Ver
    2016
    Posts
    15

    Re: Help to Sort Data Chronologically

    vba bug 2.jpg

    Yes, it shows as attached.

  19. #19
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Help to Sort Data Chronologically

    OK, your profile says Excel 2013, is that correct?

  20. #20
    Registered User
    Join Date
    10-09-2018
    Location
    Malaysia
    MS-Off Ver
    2016
    Posts
    15

    Re: Help to Sort Data Chronologically

    Excel 2016

  21. #21
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Help to Sort Data Chronologically

    For Mac or Win?

    And change the profile immediately.

  22. #22
    Registered User
    Join Date
    10-09-2018
    Location
    Malaysia
    MS-Off Ver
    2016
    Posts
    15
    Windows, what profile to change?

  23. #23
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Help to Sort Data Chronologically

    1) Your member profile.
    Click on your user name on the top next to "Welcome", you can edit your profile.

    2) change to
    Please Login or Register  to view this content.

  24. #24
    Registered User
    Join Date
    10-09-2018
    Location
    Malaysia
    MS-Off Ver
    2016
    Posts
    15

    Re: Help to Sort Data Chronologically

    1) Done, thank you for notifying me on that.
    2) It worked! Thank you so much!! Will this same code be transferable to another data set, like the one I attached?
    If changes are required, please advise.
    Attached Files Attached Files

  25. #25
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Help to Sort Data Chronologically

    Have you tried for yourself?

    It is working for me.

  26. #26
    Registered User
    Join Date
    10-09-2018
    Location
    Malaysia
    MS-Off Ver
    2016
    Posts
    15

    Re: Help to Sort Data Chronologically

    YES, it is working!! I missed a small thing though, the years should be from 2000 till 2017. Even if there is no data for 2017.
    Can that be adjusted into the code?
    I did it manually for the first data as attached.
    Thank you again!
    Attached Files Attached Files

  27. #27
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Help to Sort Data Chronologically

    Just change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  28. #28
    Forum Expert
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,513
    Quote Originally Posted by jindon View Post
    1) Your member profile.
    Click on your user name on the top next to "Welcome", you can edit your profile.

    2) change to
    Please Login or Register  to view this content.
    Master jindon is solve all problem
    "Presh Star Who has help you *For Add Reputation!! And mark case as Solve"

  29. #29
    Registered User
    Join Date
    10-09-2018
    Location
    Malaysia
    MS-Off Ver
    2016
    Posts
    15

    Re: Help to Sort Data Chronologically

    Thank you so much again jindon! Really appreciate it

  30. #30
    Forum Expert
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,513

    Re: Help to Sort Data Chronologically

    master jindon ok

+ 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. Combine 2 columns and sort chronologically
    By Sc0tt1e in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-14-2018, 11:47 AM
  2. Looking up data from different spreadsheets that are chronologically ordered
    By FJMoussally in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-07-2016, 01:40 AM
  3. Sort chronologically with formula, problem with same date
    By thorbjorn in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 02-02-2015, 02:53 PM
  4. can you pull data using VLOOKUP and list chronologically?
    By jazimm03 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-17-2014, 06:16 AM
  5. Sort Time Values Chronologically...Tricky format!
    By aloha31 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-12-2013, 04:05 PM
  6. Sort listbox chronologically
    By olivierpbeland in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-23-2013, 02:20 PM
  7. How to sort data chronologically
    By y789gh in forum Excel General
    Replies: 12
    Last Post: 03-05-2009, 09:53 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