# Add-OfficeExcelValidationTextLength

Adds a text-length data validation rule to a worksheet range.

Project

PSWriteOffice

PowerShell document automation across OfficeIMO's document, spreadsheet, presentation, PDF, Project, Access, EPUB, invoicing, and conversion engines.

[View on GitHub](https://github.com/EvotecIT/OfficeIMO/tree/master/PowerShell/PSWriteOffice) [Visit Website](#) [Releases](https://github.com/EvotecIT/PSWriteOffice/releases/tag/v3.0.5) [Changelog](#) [Get package](https://www.powershellgallery.com/packages/PSWriteOffice/0.2.0)

Stars **723**

Forks **84**

Open issues **2**

Total downloads **5,217,154**

Release **OfficeIMO-v3.6.2**

Language: C# Updated: 2026-11-23

Cmdlet 

Aliases: ExcelValidationTextLength

**Module**

`PSWriteOffice`

**Aliases**

`ExcelValidationTextLength`

**Inputs**

`OfficeIMO.Excel.ExcelDocument`

**Source**

[AddOfficeExcelValidationTextLengthCommand.cs:18](https://github.com/EvotecIT/PSWriteOffice/blob/main/Sources/PSWriteOffice/Cmdlets/Excel/AddOfficeExcelValidationTextLengthCommand.cs#L18) 

Adds a text-length data validation rule to a worksheet range.

## Syntax

```
Add-OfficeExcelValidationTextLength
[-AllowBlank <Boolean>]
[-ErrorMessage <String>]
[-ErrorTitle <String>]
[-Formula1] <Int32>
[-Formula2 <Int32>]
[-HeaderName <String>]
[-HeaderRow <Int32>]
[-IncludeHeader]
[-Operator] <ExcelDataValidationOperator>
[-PassThru]
[[-Range] <String>]
[-TableName <String>]
[<CommonParameters>]
```

[#](#method-add-officeexcelvalidationtextlength-boolean-string-string-int32-int32-string-int32-switchparameter-exceldatavalidationoperator-switchparameter-string-string)

Parameter set: `Context`

```
Add-OfficeExcelValidationTextLength
[-AllowBlank <Boolean>]
-Document <ExcelDocument>
[-ErrorMessage <String>]
[-ErrorTitle <String>]
[-Formula1] <Int32>
[-Formula2 <Int32>]
[-HeaderName <String>]
[-HeaderRow <Int32>]
[-IncludeHeader]
[-Operator] <ExcelDataValidationOperator>
[-PassThru]
[[-Range] <String>]
[-Sheet <String>]
[-SheetIndex <Int32>]
[-TableName <String>]
[<CommonParameters>]
```

[#](#method-add-officeexcelvalidationtextlength-boolean-exceldocument-string-string-int32-int32-string-int32-switchparameter-exceldatavalidationoperator-switchparameter-string-string-int32-string)

Parameter set: `Document`

## Examples

### Restrict values to 1-50 characters.

```powershell
ExcelSheet 'Data' { Add-OfficeExcelValidationTextLength -Range 'E2:E20' -Operator Between -Formula1 1 -Formula2 50 }
```

Ensures text length in E2:E20 is between 1 and 50 characters.

## Parameters

**-AllowBlank Boolean optional**

Allow blank values.

**-ErrorMessage String optional**

Error message shown to the user.

**-ErrorTitle String optional**

Error title shown to the user.

**-Formula1 Int32 requiredposition: 2**

Primary length bound.

**-Formula2 Int32 optional**

Optional secondary length bound.

**-HeaderName String optionalaliases: ColumnName**

Header or table column name used to resolve the target range.

**-HeaderRow Int32 optional**

Worksheet header row used when resolving HeaderName without a table. Use 0 for the first row of the used range.

**-IncludeHeader SwitchParameter optional**

Include the header cell in the resolved range.

**-Operator ExcelDataValidationOperator requiredposition: 1**

Validation operator.

Possible values: `Between`, `NotBetween`, `Equal`, `NotEqual`, `LessThan`, `LessThanOrEqual`, `GreaterThan`, `GreaterThanOrEqual`

**-PassThru SwitchParameter optional**

Emit the range string after applying validation.

**-Range String optionalposition: 0**

Target range in A1 notation.

**-TableName String optional**

Optional table name for header-based range resolution.

**-Document ExcelDocument requiredpipeline: True (ByValue)sets: Document**

Workbook to operate on outside the DSL context.

**-Sheet String optionalsets: Document**

Worksheet name when using Document.

**-SheetIndex Int32 optionalsets: Document**

Worksheet index (0-based) when using Document.

## 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](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters).

Evotec API Reference Copyright 2026 Evotec Services

<!-- PowerForge markdown artifact sha256:5B62707166F53B78E3C071651AF8F6944CF3A331C332C246C4095DB10F69BC41 -->
