XL.Sheet.AutoFilter.SetSort
---------------------------

Sets the sorted column in AutoFilter by zero-based index and its sort order.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [XL](component_XL.md) | [7.2](newinversion72.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "XL.Sheet.AutoFilter.SetSort"; BookRef; SheetIndex; columnIndex { ; Descending } ) 

**MBS**( **"XL.Sheet.AutoFilter.SetSort";** /\* Sets the sorted column in AutoFilter by zero-based index and its sort order. \*/  
**$BookRef**; /\* The reference number for the workbook.e.g. $ref \*/   
**$SheetIndex**; /\* The index of the sheet. This number ranges from 0 to [XL.Book.SheetCount](XLBookSheetCount.md)-1.e.g. 0 \*/   
**$columnIndex**; /\* The zero based column index.e.g. 0 \*/   
**$Descending**) /\* Optional; Whether to sort descending.  
Pass 0 for ascending and 1 for descending. Default is descending.e.g. 0 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| BookRef | The reference number for the workbook. | $ref |  |
| SheetIndex | The index of the sheet. This number ranges from 0 to [XL.Book.SheetCount](XLBookSheetCount.md)-1. | 0 |  |
| columnIndex | The zero based column index. | 0 |  |
| Descending | Whether to sort descending.   Pass 0 for ascending and 1 for descending. Default is descending. | 0 | Optional |

### Result

Returns OK or error.

### Description

Sets the sorted column in AutoFilter by zero-based index and its sort order.   
### Examples

Sort cell range with auto filter by two columns:

 Set Variable \[ $r ; Value: MBS ( "[XL.Sheet.AutoFilter](XLSheetAutoFilter.md)"; $book ; $sheet ) \]   
Set Variable \[ $r ; Value: MBS ( "[XL.Sheet.AutoFilter](XLSheetAutoFilter.md).SetRef"; $book ; $sheet ; 2; 10; 1; 4) \]   
Set Variable \[ $r ; Value: MBS ( "[XL.Sheet.AutoFilter](XLSheetAutoFilter.md).SetSort"; $book ; $sheet ; 0) \]   
Set Variable \[ $r ; Value: MBS ( "[XL.Sheet.AutoFilter](XLSheetAutoFilter.md).AddSort"; $book ; $sheet ; 1) \]   
Set Variable \[ $r ; Value: MBS ( "[XL.Sheet.ApplyFilter](XLSheetApplyFilter.md)"; $book ; $sheet ) \]  
### See also

- [XL.Book.SheetCount](XLBookSheetCount.md)
- [XL.Sheet.AutoFilter.AddSort](XLSheetAutoFilterAddSort.md)
- [XL.Sheet.AutoFilter.FilterSize](XLSheetAutoFilterFilterSize.md)
- [XL.Sheet.AutoFilter.GetRef](XLSheetAutoFilterGetRef.md)
- [XL.Sheet.AutoFilter.GetSort](XLSheetAutoFilterGetSort.md)
- [XL.Sheet.AutoFilter.GetSortRange](XLSheetAutoFilterGetSortRange.md)
- [XL.Sheet.AutoFilter.GetTop10](XLSheetAutoFilterGetTop10.md)
- [XL.Sheet.AutoFilter.SetRef](XLSheetAutoFilterSetRef.md)
- [XL.Sheet.AutoFilter.SetTop10](XLSheetAutoFilterSetTop10.md)
- [XL.Sheet.AutoFilter.SortLevels](XLSheetAutoFilterSortLevels.md)

This function checks for a license.

Created 22nd April 2017 , last changed 28th June 2022

  
[XL.Sheet.AutoFilter.SetRef](XLSheetAutoFilterSetRef.md) - [XL.Sheet.AutoFilter.SetTop10](XLSheetAutoFilterSetTop10.md)

[HTML Version](XLSheetAutoFilterSetSort.shtml)