Applying Conditional Formatting/text/scalc/guide/cellstyle_conditional.xhpconditional formatting; cellscells; conditional formattingformatting; conditional formattingstyles;conditional stylescell formats; conditionalrandom numbers;examplescell styles; copyingcopying; cell stylestables; copying cell stylesmw deleted "formats;"Applying Conditional Formatting
Using the menu command Format - Conditional - Condition, the dialog allows you to define conditions per cell, which must be met in order for the selected cells to have a particular format.To apply conditional formatting, AutoCalculate must be enabled. Choose Data - Calculate - AutoCalculate (you see a check mark next to the command when AutoCalculate is enabled).With conditional formatting, you can, for example, highlight the totals that exceed the average value of all totals. If the totals change, the formatting changes correspondingly, without having to apply other styles manually.To Define the ConditionsSelect the cells to which you want to apply a conditional style.Choose Format - Conditional - Condition.Enter the condition(s) into the dialog box. The dialog is described in detail in $[officename] Help, and an example is provided below:Example of Conditional Formatting: Highlighting Totals Above/Under the Average ValueStep1: Generate Number ValuesYou want to give certain values in your tables particular emphasis. For example, in a table of turnovers, you can show all the values above the average in green and all those below the average in red. This is possible with conditional formatting.First of all, create a table in which a few different values occur. For your test you can create tables with any random numbers:In one of the cells enter the formula =RAND(), and you will obtain a random number between 0 and 1. If you want integers of between 0 and 50, enter the formula =INT(RAND()*50).Copy the formula to create a row of random numbers. Click the bottom right corner of the selected cell, and drag to the right until the desired cell range is selected.In the same way as described above, drag down the corner of the rightmost cell in order to create more rows of random numbers.Step 2: Define Cell StylesThe next step is to apply a cell style to all values that represent above-average turnover, and one to those that are below the average. Ensure that the Styles window is visible before proceeding.Click in a blank cell and select the command Format Cells in the context menu.In the Format Cells dialog on the Background tab, click the Color button and then select a background color. Click OK.In the Styles deck of the Sidebar, click the New Style from Selection icon. Enter the name of the new style. For this example, name the style "Above".To define a second style, click again in a blank cell and proceed as described above. Assign a different background color for the cell and assign a name (for this example, "Below").Step 3: Calculate AverageIn our particular example, we are calculating the average of the random values. The result is placed in a cell:Set the cursor in a blank cell, for example, J14, and choose Insert - Function.Select the AVERAGE function. Use the mouse to select all your random numbers. If you cannot see the entire range, because the Function Wizard is obscuring it, you can temporarily shrink the dialog using the Shrink icon.Close the Function Wizard with OK.Step 4: Apply Cell StylesNow you can apply the conditional formatting to the sheet:Select all cells with the random numbers.Choose the Format - Conditional - Condition command to open the corresponding dialog.Define the condition as follows: If cell value is less than J14, format with cell style "Below", and if cell value is greater than or equal to J14, format with cell style "Above".Step 5: Copy Cell StyleTo apply the conditional formatting to other cells later:Click one of the cells that has been assigned conditional formatting.Copy the cell to the clipboard.Select the cells that are to receive this same formatting.Choose Edit - Paste Special - Paste Special. The Paste Special dialog appears.In the Paste area, check only the Formats box. All other boxes must be unchecked. Click OK. Or you can click the Formats only button instead.Format - Conditional - Condition