+ Reply to Thread
Results 1 to 12 of 12

excel vba sort by date

  1. #1
    Registered User
    Join Date
    08-13-2017
    Location
    TEL AVIV
    MS-Off Ver
    2013
    Posts
    6

    excel vba sort by date

    hi everyone,

    i'm trying to sort table by Date.
    the code is simple but i don'd get the required result:

    Please Login or Register  to view this content.
    'D1 = 01/08/2017
    'the table:
    header
    01/07/2018
    01/12/2017
    01/08/2017
    01/05/2017
    01/04/2017
    01/01/2017

    what i'm doing worng?
    thanks.
    Last edited by alansidman; 08-13-2017 at 07:54 PM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,662

    Re: excel vba sort by date

    1. Do not give variables names that look like cell addresses

    Inputboxes return character strings to variables, not dates (numbers); so, lookup the CDate function:

    Please Login or Register  to view this content.

    For the future, code tags are required for all code you post.
    Last edited by protonLeah; 08-13-2017 at 07:33 PM.
    Ben Van Johnson

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    24,010

    Re: excel vba sort by date

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Registered User
    Join Date
    08-13-2017
    Location
    TEL AVIV
    MS-Off Ver
    2013
    Posts
    6

    Re: excel vba sort by date

    1. I took your advice - thank u protonLeah
    2. alansidman - sorry my mistake its the first time i'm posting.

    back to vba:
    tried to use the CDate function & also looking for info' at the web but still dont work.
    I looked at the sort menu in at the table & its looke like excel see the variable
    dte
    as a string...

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: excel vba sort by date

    Try using CLNG vba function instead ..
    If it doesn't work please upload sample of your workbook
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  6. #6
    Registered User
    Join Date
    08-13-2017
    Location
    TEL AVIV
    MS-Off Ver
    2013
    Posts
    6

    Re: excel vba sort by date

    tried CLNG & I get dbug
    my code:
    Please Login or Register  to view this content.
    the details are:
    dte = 01/08/2017 (insert by the user)
    table:
    header
    01/07/2018
    01/12/2017
    01/08/2017
    01/05/2017
    01/04/2017
    01/01/2017

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: excel vba sort by date

    Try this code
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-13-2017
    Location
    TEL AVIV
    MS-Off Ver
    2013
    Posts
    6

    Re: excel vba sort by date

    "CDate(DateSerial"... and it working greate!
    thank u all for your assistance
    & thank u Yasser Khlil for solve it

  9. #9
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: excel vba sort by date

    You're welcome Niss. Glad I can offer some help for you
    Please mark the thread as solved
    Regards

  10. #10
    Registered User
    Join Date
    08-13-2017
    Location
    TEL AVIV
    MS-Off Ver
    2013
    Posts
    6

    Re: excel vba sort by date

    hi all,
    i open that issue again because the code work great at my laptop but not at my other computer (both excel 2013).
    any idea why? or any other solution?
    thanks.

  11. #11
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    24,010

    Re: excel vba sort by date

    Check your VBA references on the machine that works and then make sure that they are the same for the machine that does not work.

  12. #12
    Registered User
    Join Date
    08-13-2017
    Location
    TEL AVIV
    MS-Off Ver
    2013
    Posts
    6

    Re: excel vba sort by date

    Im not sure I understand, what referances do u mean?

+ 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. How to sort by day not date in Excel 2016
    By idrathernot in forum Excel General
    Replies: 6
    Last Post: 05-21-2017, 01:41 AM
  2. [SOLVED] how to sort date in excel
    By pusimani in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-16-2005, 01:00 PM
  3. [SOLVED] How do I sort worksheets in excel? i.e. Order them by date
    By Nick in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 04:05 PM
  4. How do I sort worksheets in excel? i.e. Order them by date
    By Nick in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 PM
  5. [SOLVED] How do I sort worksheets in excel? i.e. Order them by date
    By Nick in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 11:05 AM
  6. [SOLVED] How do I sort worksheets in excel? i.e. Order them by date
    By Nick in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  7. [SOLVED] Sort by date in Excel 2002?
    By Betty in forum Excel General
    Replies: 1
    Last Post: 06-02-2005, 03:05 PM

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