Running Sort macro when opening

Copper Contributor

I am trying to have this sort macro run as soon as the excel is opened. This is what my code is and i can not get it to run it when it first opens. The code works if i manually run the macro, but that defeats the purpose. 

Please tell me what im missing. 

 

 

 

Private Sub Workbook_Open()

        Application.AddCustomList ListArray:=Array("High", "CD", "Hold")
        ActiveWorkbook.Worksheets("EECR KA in work").AutoFilter.Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("EECR KA in work").AutoFilter.Sort.SortFields.Add( _
            Range("I2"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue. _
            Color = RGB(255, 0, 0)
        ActiveWorkbook.Worksheets("EECR KA in work").AutoFilter.Sort.SortFields.Add( _
            Range("I2"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue. _
            Color = RGB(250, 160, 10)
        ActiveWorkbook.Worksheets("EECR KA in work").AutoFilter.Sort.SortFields.Add2 _
            Key:=Range("I2"), SortOn:=xlSortOnValues, Order:=xlAscending, _
            CustomOrder:="High,CD,Hold", DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets("EECR KA in work").AutoFilter.Sort.SortFields.Add2 _
            Key:=Range("J2"), SortOn:=xlSortOnValues, Order:=xlAscending, _
            DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("EECR KA in work").AutoFilter.Sort
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
End Sub

 

 

 

1 Reply

@abirmingham 

Dis you create this code in the ThisWorkbook module? It will not run automatically if it is in any other module...

Do you get an error message when you open the workbook? If so, what does it say?