AllowSorting Property

Microsoft Office Web Components Visual Basic

Specifies whether a worksheet can be sorted when the worksheet has been protected. The default value is False, but this property has no effect if the Enabled property of the Protection object is set to False. Read/write Boolean.

expression.AllowSorting

expression    Required. An expression that returns a Protection object.

Example

This example locks all cells on Sheet1, enables the filtering and sorting of rows and columns, and then protects the worksheet.

Sub Protect_Worksheet()
    Dim ptProtSheet1

    'Lock all cells on the worksheet.
    Spreadsheet1.Worksheets("Sheet1").Cells.Locked = True
    
    Set ptProtSheet1 = Spreadsheet1.Worksheets("Sheet1").Protection
    
    ' Allows user to filter rows while Sheet1 is protected.
    ptProtSheet1.AllowFiltering = True
    
    ' Allows user to sort rows and columns while Sheet1 is protected.
    ptProtSheet1.AllowSorting = True
    
    ' Protect Sheet1.
    ptProtSheet1.Enabled = True
End Sub