Sort macro doesn't run itself

Apple08

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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,706
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
404
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,769
Messages
5,638,246
Members
417,016
Latest member
Tegguy

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