Link to home
Start Free TrialLog in
Avatar of Euro5
Euro5Flag for United States of America

asked on

vba sort by column error

I am getting an error on
.Columns("A:K").Sort key1:=Range("K2"), _

I have columns A-K, I am trying to sort by K, largest to smallest.
Can anyone help?

Sub Sort_count()
Application.ScreenUpdating = False
Sheets("Change Box Size").Activate
    Dim LastRow As LongPtr
    With ActiveSheet
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    End With
    
    With Application
        CalcMode = .Calculation
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
    End With
    
Range("K1") = "Index"
.Columns("A:K").Sort key1:=Range("K2"), _
order1:=xlAscending, Header:=xlYes

    With Application
        CalcMode = .Calculation
        .Calculation = xlCalculationAutomatic
        .ScreenUpdating = True
    End With
    
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Shums Faruk
Shums Faruk
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bill Prew
Bill Prew

Try:

ActiveSheet.Columns("A:K").Sort key1:=Range("K2"), _

Open in new window

~bp