I have a spreadsheet with 8 columns of data. (Row 1 contains my headers).
I am trying to record a macro that I do not have to edit afterwards.
I press record macro, I highlight my data, I go to the data tab and select sort. I then proceed to sort data in decending order by value of column D. I press stop recording macro.
When I play this macro on the same sheet, it works well. When I play this macro back on a different worksheet in the same file that is identical to the orniginal, nothing happens.
How can I record a macro to do what I would like without editing the macros in VBA?
Thanks for your help.
Sub Macro1() ' ' Macro1 Macro ' ' Cells.Select ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("D2:D1316" _ ), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal With ActiveWorkbook.Worksheets("Sheet1").Sort .SetRange Range("A1:H1316") .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With End Sub