Sort macro doesn't run itself

Apple08

Active Member
Joined
Nov 1, 2014
Messages
450
Hi All

I have recorded a sort macro but it doesn't run itself. They are stored in the data sort on menu bar, when I click ok then it runs. However I expect once I run the macro it will automatically run. Please have I done anything wrong?

VBA Code:
Cells.Select
    ActiveWorkbook.Worksheets("Data").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Data").Sort.SortFields.Add2 Key:=Range("D2:D1000") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
     ActiveWorkbook.Worksheets("Data").Sort.SortFields.Add(Range("B2:B1000"), _
        xlSortOnIcon, xlAscending, , xlSortNormal).SetIcon Icon:=ActiveWorkbook. _
        IconSets(8).Item(1)
    ActiveWorkbook.Worksheets("Data").Sort.SortFields.Add(Range("B2:B1000"), _
        xlSortOnIcon, xlAscending, , xlSortNormal).SetIcon Icon:=ActiveWorkbook. _
        IconSets(8).Item(2)
    ActiveWorkbook.Worksheets("Data").Sort.SortFields.Add(Range("B2:B1000"), _
        xlSortOnIcon, xlAscending, , xlSortNormal).SetIcon Icon:=ActiveWorkbook. _
        IconSets(8).Item(3)
    ActiveWorkbook.Worksheets("Data").Sort.SortFields.Add(Range("B2:B1000"), _
        xlSortOnFontColor, xlDescending, , xlSortNormal).SortOnValue.Color = RGB(0, 0, _
        0)
    With ActiveWorkbook.Worksheets("Data").Sort
        .SetRange Range("A1:J1000")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
        
    End With
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Why do you think a macro would run itself?
 
Upvote 0
Sorry, please ignore my question as I have put the macro in the wrong order, I have now fixed it. Thanks.
 
Upvote 0
Solution

Forum statistics

Threads
1,213,561
Messages
6,114,317
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top