Avatar of david francisco
david francisco
Flag for United States of America

asked on 

VBA Excel Sort

I am attempting to have a vba code check the dates in column b and arrange them from soonest to latest. The code I have so far is
    Range("B1:B37").Select
    ActiveWorkbook.Worksheets("FUN1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("FUN1").Sort.SortFields.Add Key:=Range("B1"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("FUN1").Sort
        .SetRange Range("A1:C10")
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With

Open in new window


And this code seems to sort the data, but not always in order. An example of the data I am working with is:

RED                11/28/2017                7.99
BLUE              11/25/2017               10.99            
BLUE              11/26/2017               10.99
RED                12/15/2017                7.99
ORANGE        11/30/2017               13.99
GREEN           12/28/2017                5.99


And the desired output is:

BLUE              11/25/2017               10.99
BLUE              11/26/2017               10.99
RED                11/28/2017                7.99
ORANGE        11/30/2017               13.99
RED                12/15/2017                7.99
GREEN           12/28/2017                5.99
VBAMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
david francisco

8/22/2022 - Mon