[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Collapse]Office File API
  Demo Application
  Redistribution and Deployment
 [Collapse]Spreadsheet Document API
   Product Structure
   Getting Started
  [Expand]Spreadsheet Document
   Supported Formats
  [Expand]Cell Basics
  [Expand]Formulas
   Defined Names
   Data Binding
  [Expand]Pivot Tables
  [Expand]Charts and Graphics
  [Expand]Mail Merge
  [Collapse]Examples
   [Expand]Files
   [Expand]Workbooks
   [Expand]Worksheets
   [Expand]Rows and Columns
   [Expand]Cells
   [Expand]Formulas
   [Expand]Import and Export Data
   [Expand]Data Binding
    Sorting
   [Expand]Mail Merge
    Search
   [Expand]Shapes
   [Expand]Charts
   [Expand]Sparklines
   [Expand]Formatting Cells
   [Collapse]Conditional Formatting
     How to: Format Cell Values that are Above or Below the Average
     How to: Format Cells that are Between or Not Between Two Values
     How to: Format Top or Bottom Ranked Values
     How to: Format Cells based on the Text in the Cell
     How to: Format Unique or Duplicate Values, Blank Cells and Formula Errors
     How to: Format Cells that Contain Dates
     How to: Format Cells that are Less than, Greater than or Equal to a Value
     How to: Use a Formula to Determine which Cells to Format
     How to: Format Cells Using a Two-Color Scale
     How to: Format Cells Using a Three-Color Scale
     How to: Format Cells Using Data Bars
     How to: Format Cells Using Icon Sets
   [Expand]Group Data
   [Expand]Filter Data
   [Expand]Tables
   [Expand]Pivot Tables
   [Expand]Printing
   [Expand]Pictures
   [Expand]Protection
 [Expand]Word Processing Document API
 [Expand]PDF Document API
 [Expand]Excel Export Library
 [Expand]Snap Report API
 [Expand]Zip Compression and Archive API
 [Expand]Barcode Generation API
 [Expand]Unit Conversion API
 [Expand]API Reference
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How to: Format Cells that are Between or Not Between Two Values

This example demonstrates how to apply the conditional formatting rule, highlighting cells that are between or not between two values.

  1. To create a new conditional formatting rule represented by the RangeConditionalFormatting object, access the collection of conditional formats from the Worksheet.ConditionalFormattings property and call the ConditionalFormattingCollection.AddRangeConditionalFormatting method. Pass the following parameters:

    • A Range object that defines a range of cells to which the rule is applied.
    • A condition specified by one of the ConditionalFormattingRangeCondition enumeration values.
    • A string representing the low bound of the data subset inside or outside of which, formatted cells are located. Notice that the string can determine a formula to evaluate the lowest value.
    • A string representing the high bound of the data subset inside or outside of which, formatted cells are located. Notice that the string can determine a formula to evaluate the highest value.
  2. Specify formatting options to be applied to cells if the condition is true using the ISupportsFormatting.Formatting property of the RangeConditionalFormatting object. Set the background and font colors.

To remove the RangeConditionalFormatting object, use the ConditionalFormattingCollection.Remove, ConditionalFormattingCollection.RemoveAt or ConditionalFormattingCollection.Clear methods.

The image below shows the result (the workbook is opened in Microsoft® Excel®). Price values below $7 and above $19 are colored in yellow, and the font color is changed to red.

Is this topic helpful?​​​​​​​