# Compare-OfficeExcelRange

Compares two worksheets or ranges cell by cell. Review available syntax, parameters, pipeline guidance, and reference details in PSWriteOffice Cmdlet Reference.

Cmdlet 

**Module**

`PSWriteOffice`

**Inputs**

`OfficeIMO.Excel.ExcelDocument`

**Source**

[CompareOfficeExcelRangeCommand.cs:34](https://github.com/EvotecIT/OfficeIMO/blob/be6c300e4ab1859837b961c64fbfb2b2a1886cd0/PowerShell/PSWriteOffice/Sources/PSWriteOffice/Cmdlets/Excel/CompareOfficeExcelRangeCommand.cs#L34) 

Compares two worksheets or ranges cell by cell.

## Syntax

```
Compare-OfficeExcelRange
[[-DifferencePath] <String>]
[-DifferenceRange <String>]
[-DifferenceSheet <OfficeSheetSelector>]
[-IgnoreCase]
[-Range <String>]
[-ReferencePath] <String>
[-Sheet <OfficeSheetSelector>]
[-StrictNullEmpty]
[-TrimStrings]
[<CommonParameters>]
```

[#](#method-compare-officeexcelrange-string-string-officesheetselector-switchparameter-string-string-officesheetselector-switchparameter-switchparameter)

Parameter set: `Path`

```
Compare-OfficeExcelRange
[-DifferenceDocument <ExcelDocument>]
[-DifferenceRange <String>]
[-DifferenceSheet <OfficeSheetSelector>]
[-IgnoreCase]
[-Range <String>]
-ReferenceDocument <ExcelDocument>
[-Sheet <OfficeSheetSelector>]
[-StrictNullEmpty]
[-TrimStrings]
[<CommonParameters>]
```

[#](#method-compare-officeexcelrange-exceldocument-string-officesheetselector-switchparameter-string-exceldocument-officesheetselector-switchparameter-switchparameter)

Parameter set: `Document`

## Guides & Samples

Authored walkthroughs and practical samples linked to this command.

- [Automate Excel Workbooks](/docs/pswriteoffice/excel/) Guide
  
  Build, inspect, validate, compare, repair, and publish workbook workflows from PowerShell. Includes examples and cmdlet links.
- [Merge and Compare Excel Workbooks](/docs/pswriteoffice/excel-merge-compare/) Guide
  
  Consolidate selected worksheets and produce explicit workbook or range differences for review and delivery gates.

## Examples

### Compare a sheet in two versions

```powershell
Compare-OfficeExcelRange -ReferencePath .\Finance\Budget-v1.xlsx -DifferencePath .\Finance\Budget-v2.xlsx -Sheet Budget |
                Select-Object Kind, ReferenceCell, ReferenceValue, DifferenceValue
```

Lists the cells of the Budget sheet that differ between two versions of the workbook.

### Reconcile two lists in one workbook

```powershell
$compare = @{
    ReferencePath   = '.\Finance\Reconciliation-October.xlsx'
    Sheet           = 'Ledger'
    Range           = 'A1:F400'
    DifferenceSheet = 'Bank'
    DifferenceRange = 'A1:F400'
}
Compare-OfficeExcelRange @compare -TrimStrings -IgnoreCase |
    Export-OfficeExcel -Path .\Finance\Reconciliation-Differences.xlsx -Title 'Ledger and bank differences'
```

Compares the ledger with the bank statement range by range, ignoring case and stray spaces, and writes the differences to a review workbook.

## Parameters

**-DifferencePath String optionalposition: 1sets: Path**

Workbook path to compare against.

**-DifferenceRange String optional**

A1 range containing the comparison values in the difference workbook.

**-DifferenceSheet OfficeSheetSelector optional**

Worksheet selector in the difference workbook.

**-IgnoreCase SwitchParameter optional**

Compare strings case-insensitively.

**-Range String optional**

A1 cell range on the selected worksheet.

**-ReferencePath String requiredposition: 0sets: Path**

Path to the workbook containing the reference values.

**-Sheet OfficeSheetSelector optional**

Worksheet name, one-based position or native worksheet object. Multi-sheet commands also accept wildcard names.

**-StrictNullEmpty SwitchParameter optional**

Treat null and empty string values as different.

**-TrimStrings SwitchParameter optional**

Compare strings after trimming whitespace.

**-DifferenceDocument ExcelDocument optionalsets: Document**

Workbook document to compare against.

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

Caller-owned workbook containing the reference values.

## 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).

<!-- PowerForge markdown artifact sha256:4C1EA045C5A67D79AF7FD3620ADF3857D91A119D59418BCCD4BA819FAB20BFCA -->
