We help IT Professionals succeed at work.
Get Started

VBA Excel Sort

184 Views
Last Modified: 2018-02-02
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
Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 6 Answers and 9 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE