XL.Sheet.AutoFilter.AddFilter
-----------------------------

Adds the filter value.

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

MBS( "XL.Sheet.AutoFilter.AddFilter"; BookRef; SheetIndex; FilterColumnIndex; Filter ) 

**MBS**( **"XL.Sheet.AutoFilter.AddFilter";** /\* Adds the filter value. \*/  
**$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 \*/   
**$FilterColumnIndex**; /\* The column index of the filter.  
Range from 0 to [XL.Sheet.AutoFilter](XLSheetAutoFilter.md).ColumnSize-1.e.g. $FilterColumn \*/   
**$Filter**) /\* The filter value. \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| 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 |
| FilterColumnIndex | The column index of the filter.   Range from 0 to [XL.Sheet.AutoFilter](XLSheetAutoFilter.md).ColumnSize-1. | $FilterColumn |
| Filter | The filter value. |  |

### Result

Returns OK or error.

### Description

Adds the filter value.  
### Examples

Add filters:

 Set Variable \[ $r ; Value: MBS ( "[XL.Sheet.AutoFilter](XLSheetAutoFilter.md).AddFilter"; $book ; $sheet ; 0; "Japan") \]   
Set Variable \[ $r ; Value: MBS ( "[XL.Sheet.AutoFilter](XLSheetAutoFilter.md).AddFilter"; $book ; $sheet ; 0; "USA") \]   
Set Variable \[ $r ; Value: MBS ( "[XL.Sheet.AutoFilter](XLSheetAutoFilter.md).AddFilter"; $book ; $sheet ; 0; "Switzerland") \]  
Add filter with a list of values:

 # AUTO FILTER: :: Applies the AutoFilter to the sheet   
Set Variable \[ $r ; Value: MBS ( "[XL.Sheet.AutoFilter](XLSheetAutoFilter.md)"; $book ; $sheet ) \]   
\#   
\# Select Cells :: Sets the cell range of AutoFilter with header.   
Set Variable \[ $r ; Value: MBS ( "[XL.Sheet.AutoFilter](XLSheetAutoFilter.md).SetRef"; $book ; $sheet ; $headerRow ; $lastRow ; 4; 4 ) \]   
\#   
\# Add Filter :: Adds the filter values from a values list.   
Set Variable \[ $filterCount ; Value: ValueCount ( $FilterValues ) \]   
Set Variable \[ $filterIndex ; Value: 1 \]   
Loop  
 Set Variable \[ $filterValue ; Value: GetValue($filterValues ; $filterIndex ) \]   
 Set Variable \[ $r ; Value: MBS ( "[XL.Sheet.AutoFilter](XLSheetAutoFilter.md).AddFilter"; $book ; $sheet ; 0; $filterValue ) \]   
 #   
 # next  
 Set Variable \[ $filterIndex ; Value: $filterIndex + 1 \]   
 Exit Loop If \[ $filterIndex &gt; $filterCount \]   
End Loop  
\#   
\# Apply Filter :: Applies the AutoFilter to the sheet   
Set Variable \[ $r ; Value: MBS ( "[XL.Sheet.ApplyFilter](XLSheetApplyFilter.md)"; $book ; $sheet ) \]  
Use two filtered columns:

 Set Variable \[ $r ; Value: MBS ( "[XL.Sheet.AutoFilter](XLSheetAutoFilter.md)"; $book ; $sheet ) \]   
\# pick area to use for filter   
Set Variable \[ $r ; Value: MBS ( "[XL.Sheet.AutoFilter](XLSheetAutoFilter.md).SetRef"; $book ; $sheet ; 2; 10; 1; 4) \]   
\# filter first column in the set   
Set Variable \[ $r ; Value: MBS ( "[XL.Sheet.AutoFilter](XLSheetAutoFilter.md).AddFilter"; $book ; $sheet ; 0; "USA") \]   
Set Variable \[ $r ; Value: MBS ( "[XL.Sheet.AutoFilter](XLSheetAutoFilter.md).AddFilter"; $book ; $sheet ; 0; "Japan") \]   
\# and filter second column in the reference area   
Set Variable \[ $r ; Value: MBS ( "[XL.Sheet.AutoFilter](XLSheetAutoFilter.md).AddFilter"; $book ; $sheet ; 1; "64") \]   
\# apply it!   
Set Variable \[ $r ; Value: MBS ( "[XL.Sheet.ApplyFilter](XLSheetApplyFilter.md)"; $book ; $sheet ) \]  
### See also

- [XL.Book.SheetCount](XLBookSheetCount.md)
- [XL.Sheet.ApplyFilter](XLSheetApplyFilter.md)
- [XL.Sheet.AutoFilter.AddSort](XLSheetAutoFilterAddSort.md)
- [XL.Sheet.AutoFilter.Filter](XLSheetAutoFilterFilter.md)
- [XL.Sheet.AutoFilter.FilterSize](XLSheetAutoFilterFilterSize.md)
- [XL.Sheet.AutoFilter.GetSort](XLSheetAutoFilterGetSort.md)
- [XL.Sheet.AutoFilter.GetSortEx](XLSheetAutoFilterGetSortEx.md)
- [XL.Sheet.AutoFilter.SetCustomFilter](XLSheetAutoFilterSetCustomFilter.md)
- [XL.Sheet.AutoFilter.SetRef](XLSheetAutoFilterSetRef.md)
- [XL.Sheet.AutoFilter.SetSort](XLSheetAutoFilterSetSort.md)

This function checks for a license.

Created 1st July 2017 , last changed 11st November 2022

  
[XL.Sheet.AutoFilter](XLSheetAutoFilter.md) - [XL.Sheet.AutoFilter.AddSort](XLSheetAutoFilterAddSort.md)

[HTML Version](XLSheetAutoFilterAddFilter.shtml)