We help IT Professionals succeed at work.
Get Started

Decoding a line of VBA DataSort

Last Modified: 2017-03-28
WS.Range("B3:C" & MaxRow).Sort Key1:=WS.Range("C3"), order1:=xlAscending, MatchCase:=False, Header:=xlYes

Does WS need to have a value?
I am trying to sort a dataset by column F, that starts at row 2 with headers and I wanted to use this for a dynamic range.

Trying to sort Largest to Smallest

This is what the recorder recorded.
        ActiveWorkbook.Worksheets("CountSummary").Sort.SortFields.Add Key:=Range( _
            "F2:F89"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
        With ActiveWorkbook.Worksheets("CountSummary").Sort
            .SetRange Range("A1:Y89")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
        End With

Open in new window

Ln 6 will not work, in a dynamic dataset.  Any ideas?
Watch Question
Excel VBA Developer
Distinguished Expert 2018
This problem has been solved!
Unlock 1 Answer and 11 Comments.
See Answer
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