Forum Discussion
Macro not activating
- Jul 23, 2024
Do you update the data in the deviation masterlist sheet manually? If so, the code should work if it is placed in the worksheet module of that sheet (not in the worksheet module of the ranked masterlist sheet!)
But I'd prefer to sort the ranked masterlist sheet when it is activated:
Right-click the sheet tab of the ranked masterlist sheet.
Select View Code from the context menu.
Copy the following code into the worksheet module:
Private Sub Worksheet_Activate() With Me.Sort .SortFields.Clear .SortFields.Add2 Key:=Range("B1"), SortOn:=xlSortOnValues, _ Order:=xlDescending, DataOption:=xlSortNormal .SortFields.Add2 Key:=Range("F1"), SortOn:=xlSortOnValues, _ Order:=xlDescending, DataOption:=xlSortTextAsNumbers .SetRange Range("B1").CurrentRegion .Header = xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With End Sub
Do you update the data in the deviation masterlist sheet manually? If so, the code should work if it is placed in the worksheet module of that sheet (not in the worksheet module of the ranked masterlist sheet!)
But I'd prefer to sort the ranked masterlist sheet when it is activated:
Right-click the sheet tab of the ranked masterlist sheet.
Select View Code from the context menu.
Copy the following code into the worksheet module:
Private Sub Worksheet_Activate()
With Me.Sort
.SortFields.Clear
.SortFields.Add2 Key:=Range("B1"), SortOn:=xlSortOnValues, _
Order:=xlDescending, DataOption:=xlSortNormal
.SortFields.Add2 Key:=Range("F1"), SortOn:=xlSortOnValues, _
Order:=xlDescending, DataOption:=xlSortTextAsNumbers
.SetRange Range("B1").CurrentRegion
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End SubHansVogelaarOh, thank you! I'd placed the code in the workbook's module, I didn't realise individual sheets could have their own modules (or that it would matter). It works now, so many thanks!