Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Set-OfficeExcelAutoFilter

Aliases: ExcelAutoFilter
Module
PSWriteOffice
Aliases
ExcelAutoFilter
Inputs
OfficeIMO.Excel.ExcelDocument

Adds an AutoFilter to a range and applies filter conditions.

Syntax

Set-OfficeExcelAutoFilter
[-Criteria <Hashtable>]
[-Document <ExcelDocument>]
[-PassThru]
[-Range] <String>
[-Sheet <OfficeSheetSelector>]
[<CommonParameters>]
#
Parameter set: Range
Set-OfficeExcelAutoFilter
[-Between <Double[]>]
[-Contains <String>]
[-Document <ExcelDocument>]
[-DoesNotContain <String>]
[-EndsWith <String>]
[-GreaterThanOrEqual <Double>]
[-Header] <String>
[-LessThanOrEqual <Double>]
[-NotBetween <Double[]>]
[-NotEqual <Double>]
[-PassThru]
[-Range <String>]
[-Sheet <OfficeSheetSelector>]
[-StartsWith <String>]
[-Value <String[]>]
[<CommonParameters>]
#
Parameter set: Condition

Examples

Add filter buttons to a range

Open-OfficeExcel -Path .\Reports\Inventory.xlsx {
    ExcelSheet 'Servers' {
        ExcelAutoFilter A1:F500
    }
}

Adds AutoFilter drop-downs to the header row of A1:F500.

Open a sheet filtered to the open work

Open-OfficeExcel -Path .\Reports\Helpdesk.xlsx {
    ExcelSheet 'Tickets' {
        ExcelAutoFilter -Header Status -Value 'Open', 'On hold'
        ExcelAutoFilter -Header AgeDays -GreaterThanOrEqual 3
    }
}

Filters the ticket list to the Open and On hold statuses with at least three days of age, so the sheet opens on the work that needs attention.

Filter a new range by header names

Open-OfficeExcel -Path .\Reports\Helpdesk.xlsx {
    ExcelSheet 'Tickets' {
        ExcelAutoFilter A1:H900 -Criteria @{ Status = 'Open', 'On hold'; Region = 'EMEA' }
    }
}

Adds filter buttons and immediately shows only open EMEA tickets.

Parameters

-Criteria Hashtable optionalsets: Range
Maps header names to filter values, value lists or comparison criteria.
-Document ExcelDocument optionalpipeline: True (ByValue)
Caller-owned workbook; omission uses the enclosing Excel content block.
-PassThru SwitchParameter optional
Emits the native result after the operation.
-Range String required in Rangeposition: 0
A1 cell range on the selected worksheet.
-Sheet OfficeSheetSelector optional
Worksheet name, one-based position or native worksheet object. Multi-sheet commands also accept wildcard names.
-Between Double[] optionalsets: Condition
Inclusive numeric range condition. Provide exactly two values: minimum, maximum.
-Contains String optionalsets: Condition
Text that the column value must contain.
-DoesNotContain String optionalsets: Condition
Text that the column value must not contain.
-EndsWith String optionalsets: Condition
Text that the column value must end with.
-GreaterThanOrEqual Double optionalsets: Condition
Numeric greater-than-or-equal condition.
-Header String requiredposition: 0sets: Condition
Header text identifying the target column.
-LessThanOrEqual Double optionalsets: Condition
Numeric less-than-or-equal condition.
-NotBetween Double[] optionalsets: Condition
Outside numeric range condition. Provide exactly two values: minimum, maximum.
-NotEqual Double optionalsets: Condition
Numeric not-equal condition.
-StartsWith String optionalsets: Condition
Text that the column value must start with.
-Value String[] optionalsets: Condition
Value or values consumed by the selected operation.

Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see about_CommonParameters.