Sort macro doesn't run itself

Apple08

Active Member
Joined
Nov 1, 2014
Messages
403
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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,692
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Why do you think a macro would run itself?
 

Apple08

Active Member
Joined
Nov 1, 2014
Messages
403
Sorry, please ignore my question as I have put the macro in the wrong order, I have now fixed it. Thanks.
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,129,285
Messages
5,635,324
Members
416,854
Latest member
jaywrye

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
Top