0

I have to sort columns in Excel on their values.

I worked out the following procedure:

With calcCalculations

    With .Sort    
        .SortFields.Add Key:=Range("BR2:BR5000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        .SortFields.Add Key:=Range("BV2:BV5000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        .SortFields.Add Key:=Range("CA2:CA5000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        .SortFields.Add Key:=Range("CD2:CD5000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

        .SetRange Range("BR:CD")
        .Header = xlYes
        .MatchCase = True
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
    End With

End with

The procedure does not error out, but it is not sorting my data.

1
  • 1
    At the end, .apply otherwise you only set. Commented Aug 6, 2014 at 5:43

2 Answers 2

2

As user3514930 said: You're missing the .Apply before the End With

Sign up to request clarification or add additional context in comments.

Comments

1
                With calcCalculations

With .Sort

.SortFields.Add Key:=Range("BR2:BR5000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add Key:=Range("BV2:BV5000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add Key:=Range("CA2:CA5000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add Key:=Range("CD2:CD5000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

         .SetRange Range("BR:CD")
         .Header = xlYes
         .MatchCase = True
         .Orientation = xlTopToBottom
         .SortMethod = xlPinYin
         .Apply
        End With

End with

As the other users said.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.