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
david franciscoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roy CoxGroup Finance ManagerCommented:
An example workbook would be helpful
0
david franciscoAuthor Commented:
I unfortunately do not have access to the original workbook on this PC
0
Martin LissOlder than dirtCommented:
I created a workbook that included the unsorted data you show. When I ran your code it produced the desired output so something else must be going on.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Martin LissOlder than dirtCommented:
Here's a copy of that workbook. Note that sheet 'FUN1 (2)' is a backup copy of the unsorted data.
29070277.xlsm
0
Ejgil HedegaardCommented:
If the dates are text, and not real dates, the sort will be wrong.
Select the dates in column B, and use "Text to columns" on the data tab.
Then try again.

You can also make a formula in column D
=ISNUMBER(B1)
Should return True.
If not use above.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
david franciscoAuthor Commented:
When I apply another line, it will refresh like this:

 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
 RED                12/30/2017                7.99
 GREEN           12/6/2017                5.99
 ORANGE        12/15/2017               13.99

The last red in the sequence is not being placed as the last item
0
Martin LissOlder than dirtCommented:
Once again when I run your code it works correctly for me.
0
Martin LissOlder than dirtCommented:
Ejgil is correct. If I manually type in the 'dates' in a column formatted as Text, the sorting does not work properly.
0
david franciscoAuthor Commented:
Fair enough, I will try to trouble shoot. Thanks for the support!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.