Results 1 to 3 of 3
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    sort dates in array (2000)

    after ciclcling of sheets X is filled with unique value.
    now with the value in X is possble to sort this array by date ascending?

    I think the call: Call GetDates(X)
    not work correct...

  2. #2
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: sort dates in array (2000)

    I think you will find the answer here,

    http://www.xtremevbtalk.com/showthread.php?t=296841

    The code they give you and advice presented seems quite sensible
    Jerry

  3. #3
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: sort dates in array (2000)

    1 problem is that you are using col A to set the "Ultima" row and with no values in A, ULTIMA is one which means you get the wrong values and you include the header in the array. Use the line:
    ULTIMA = Sheets(FOGLIO).Cells(Rows.Count, <font color=red>8</font color=red>).End(xlUp).Row

    to base it on column H which is the range of the combobox

    The other problems stem from the X array being TEXT and so the dates will sort wrong since it will sort by DAY, month, then year when you want to sort by YEAR, month, then day. Compounding the problem is that while X starts out with all text values, some of the values, get turned into dates since TEMP is dimmed as a date. Thus you have a mixture of dates and text which screws up the comparison and the comparison which change when it gets transformed.

    To solve this, you can convert all the text into dates before you sort it, by looping through the array and put each item into TEMP to convert them and then put them back into the array, then do the sort

    <pre> First = LBound(X)
    Last = UBound(X)
    <font color=red>For i = First To Last
    Temp = X(i)
    X(i) = Temp
    Next</font color=red>
    For i = First To Last - 1</pre>


    Steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •