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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
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,214,948
Messages
6,122,420
Members
449,083
Latest member
Ava19

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