Data on a protected sheet can be sorted if they are within a range where the Locked property is set to False, and if the AllowSorting parameter of the Protect method is set to True.
The read-only property AllowSorting of the Protection object returns the value of this parameter. For example, the code allows sorting the range A1:A5 on a protected sheet, if it has not been enabled previously.
Sorting on a Protected Sheet
Sub DemoAllowSorting()
ActiveSheet.Unprotect
Range("A1:A5").Locked = False
If ActiveSheet.Protection.AllowSorting Then
ActiveSheet.Protect AllowSorting:=True
End If
End Sub