troubleshooting Question

Decoding a line of VBA DataSort

Avatar of RWayneH
RWayneHFlag for United States of America asked on
VBAMicrosoft ExcelMicrosoft Office
11 Comments1 Solution122 ViewsLast Modified:
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.Clear
        ActiveWorkbook.Worksheets("CountSummary").Sort.SortFields.Add Key:=Range( _
            "F2:F89"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("CountSummary").Sort
            .SetRange Range("A1:Y89")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With

Ln 6 will not work, in a dynamic dataset.  Any ideas?
ASKER CERTIFIED SOLUTION
Shums
Excel VBA Developer
Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros