Cmdlet
Add-OfficeExcelValidation
Adds a data validation rule to a range or a header column.
Syntax
Add-OfficeExcelValidation
[-Document <ExcelDocument>]
[-ErrorMessage <String>]
[-ErrorTitle <String>]
[-NoBlank]
[-PassThru]
[-Prompt <String>]
[-PromptTitle <String>]
[-Range] <String>
[-Sheet <OfficeSheetSelector>]
[-Type] <ExcelValidationType>
[-Values] <String[]>
[<CommonParameters>]#Parameter set:
ListRangeAdd-OfficeExcelValidation
[-Document <ExcelDocument>]
[-ErrorMessage <String>]
[-ErrorTitle <String>]
[-NoBlank]
-Operator <ExcelDataValidationOperator>
[-PassThru]
[-Prompt <String>]
[-PromptTitle <String>]
[-Range] <String>
[-SecondValue <Object>]
[-Sheet <OfficeSheetSelector>]
[-Type] <ExcelValidationType>
[-Value] <Object>
[<CommonParameters>]#Parameter set:
CompareRangeAdd-OfficeExcelValidation
[-Document <ExcelDocument>]
[-ErrorMessage <String>]
[-ErrorTitle <String>]
[-Formula] <String>
[-NoBlank]
[-PassThru]
[-Prompt <String>]
[-PromptTitle <String>]
[-Range] <String>
[-Sheet <OfficeSheetSelector>]
[-Type] <ExcelValidationType>
[<CommonParameters>]#Parameter set:
FormulaRangeAdd-OfficeExcelValidation
[-Document <ExcelDocument>]
[-ErrorMessage <String>]
[-ErrorTitle <String>]
-Header <String>
[-HeaderRow <Int32>]
[-IncludeHeader]
[-NoBlank]
[-PassThru]
[-Prompt <String>]
[-PromptTitle <String>]
[-Sheet <OfficeSheetSelector>]
[-Table <String>]
[-Type] <ExcelValidationType>
[-Values] <String[]>
[<CommonParameters>]#Parameter set:
ListHeaderAdd-OfficeExcelValidation
[-Document <ExcelDocument>]
[-ErrorMessage <String>]
[-ErrorTitle <String>]
-Header <String>
[-HeaderRow <Int32>]
[-IncludeHeader]
[-NoBlank]
-Operator <ExcelDataValidationOperator>
[-PassThru]
[-Prompt <String>]
[-PromptTitle <String>]
[-SecondValue <Object>]
[-Sheet <OfficeSheetSelector>]
[-Table <String>]
[-Type] <ExcelValidationType>
[-Value] <Object>
[<CommonParameters>]#Parameter set:
CompareHeaderAdd-OfficeExcelValidation
[-Document <ExcelDocument>]
[-ErrorMessage <String>]
[-ErrorTitle <String>]
[-Formula] <String>
-Header <String>
[-HeaderRow <Int32>]
[-IncludeHeader]
[-NoBlank]
[-PassThru]
[-Prompt <String>]
[-PromptTitle <String>]
[-Sheet <OfficeSheetSelector>]
[-Table <String>]
[-Type] <ExcelValidationType>
[<CommonParameters>]#Parameter set:
FormulaHeaderExamples
Restrict a column to a list
Open-OfficeExcel -Path .\Reports\Helpdesk.xlsx {
ExcelSheet 'Tickets' {
ExcelValidation -Range C2:C500 -Type List -Values 'Open', 'In progress', 'On hold', 'Closed'
}
}Adds a drop-down that allows only the listed statuses in C2:C500.
Validate quantities in a request form
Open-OfficeExcel -Path .\Forms\Equipment-Requests.xlsx {
ExcelSheet 'Requests' {
ExcelValidation -Header Quantity -Table Requests -Type WholeNumber -Operator Between -Value 1 -SecondValue 500 -NoBlank -ErrorTitle 'Quantity' -ErrorMessage 'Enter a whole number from 1 to 500.'
}
}Allows whole numbers from 1 to 500 in the Quantity column of the Requests table and explains the rule when a wrong value is typed.
Validate with a formula
Open-OfficeExcel -Path .\Projects\Plan.xlsx {
ExcelSheet 'Tasks' {
ExcelValidation -Range D2:D300 -Type Formula -Formula '=D2>=C2' -ErrorMessage 'The end date must be on or after the start date.'
}
}Rejects end dates that come before the start date in the same row.
Parameters
- -Document ExcelDocument
- Caller-owned workbook; omission uses the enclosing Excel content block.
- -ErrorMessage String
- Error message shown to the user.
- -ErrorTitle String
- Error title shown to the user.
- -NoBlank SwitchParameter
- Rejects blank input in the validation rule.
- -PassThru SwitchParameter
- Emits the native result after the operation.
- -Prompt String
- Input prompt text. Omit or pass null to clear the prompt.
- -PromptTitle String
- Input prompt title. Omit or pass null to clear the title.
- -Range String
- A1 cell range on the selected worksheet.
- -Sheet OfficeSheetSelector
- Worksheet name, one-based position or native worksheet object. Multi-sheet commands also accept wildcard names.
- -Type ExcelValidationType
- Shared chart family. Bubble requires the separate native bubble-data contract.
- Possible values:
List,WholeNumber,Decimal,Date,Time,TextLength,Formula - -Values String[]
- Allowed values for the dropdown list.
- -Operator ExcelDataValidationOperator
- Validation operator.
- Possible values:
Between,NotBetween,Equal,NotEqual,LessThan,LessThanOrEqual,GreaterThan,GreaterThanOrEqual - -SecondValue Object
- Upper bound or second formula used by between comparisons.
- -Value Object
- Value or values consumed by the selected operation.
- -Formula String
- Validation formula.
- -Header String
- Header text identifying the target column.
- -HeaderRow Int32
- One-based row containing the column headers.
- -IncludeHeader SwitchParameter
- Includes the header cell in the resolved column range.
- -Table String
- Native Excel table used to resolve the source range or header.
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.