1<?xml version="1.0" encoding="UTF-8"?>
2<helpdocument version="1.0">
3
4<!--***********************************************************
5 *
6 * Licensed to the Apache Software Foundation (ASF) under one
7 * or more contributor license agreements.  See the NOTICE file
8 * distributed with this work for additional information
9 * regarding copyright ownership.  The ASF licenses this file
10 * to you under the Apache License, Version 2.0 (the
11 * "License"); you may not use this file except in compliance
12 * with the License.  You may obtain a copy of the License at
13 *
14 *   http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an
18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 * KIND, either express or implied.  See the License for the
20 * specific language governing permissions and limitations
21 * under the License.
22 *
23 ***********************************************************-->
24
25
26
27
28<meta>
29      <topic id="textscalcguidecellstyle_by_formulaxml" indexer="include" status="PUBLISH">
30         <title xml-lang="en-US" id="tit">Assigning Formats by Formula</title>
31         <filename>/text/scalc/guide/cellstyle_by_formula.xhp</filename>
32      </topic>
33   </meta>
34   <body>
35<bookmark xml-lang="en-US" branch="index" id="bm_id3145673"><bookmark_value>formats; assigning by formulas</bookmark_value>
36      <bookmark_value>cell formats; assigning by formulas</bookmark_value>
37      <bookmark_value>STYLE function example</bookmark_value>
38      <bookmark_value>cell styles;assigning by formulas</bookmark_value>
39      <bookmark_value>formulas;assigning cell formats</bookmark_value>
40</bookmark><comment>mw deleted "applying;"</comment>
41<paragraph xml-lang="en-US" id="hd_id3145673" role="heading" level="1" l10n="U"
42                 oldref="13"><variable id="cellstyle_by_formula"><link href="text/scalc/guide/cellstyle_by_formula.xhp" name="Assigning Formats by Formula">Assigning Formats by Formula</link>
43</variable></paragraph>
44      <paragraph xml-lang="en-US" id="par_id3150275" role="paragraph" l10n="CHG" oldref="14">The STYLE() function can be added to an existing formula in a cell. For example, together with the CURRENT function, you can color a cell depending on its value. The formula =...+STYLE(IF(CURRENT()&gt;3; "Red"; "Green")) applies the cell style "Red" to cells if the value is greater than 3, otherwise the cell style "Green" is applied.</paragraph>
45      <paragraph xml-lang="en-US" id="par_id3151385" role="paragraph" l10n="U" oldref="15">If you would like to apply a formula to all cells in a selected area, you can use the<emph/>
46         <item type="menuitem">Find &amp; Replace</item> dialog.</paragraph>
47      <list type="ordered">
48         <listitem>
49            <paragraph xml-lang="en-US" id="par_id3149456" role="listitem" l10n="U" oldref="16">Select all the desired cells.</paragraph>
50         </listitem>
51         <listitem>
52            <paragraph xml-lang="en-US" id="par_id3148797" role="listitem" l10n="U" oldref="17">Select the menu command <emph>Edit - Find &amp; Replace</emph>.</paragraph>
53         </listitem>
54         <listitem>
55            <paragraph xml-lang="en-US" id="par_id3150767" role="listitem" l10n="U" oldref="18">For the <item type="menuitem">Search for</item> term, enter: .<item type="literal">*</item>
56            </paragraph>
57            <paragraph xml-lang="en-US" id="par_id3153770" role="listitem" l10n="U" oldref="19">".*" is a regular expression that designates the contents of the current cell.</paragraph>
58         </listitem>
59         <listitem>
60            <paragraph xml-lang="en-US" id="par_id3153143" role="listitem" l10n="U" oldref="20">Enter the following formula in the <item type="menuitem">Replace with</item> field: <item type="literal">=&amp;+STYLE(IF(CURRENT()&gt;3;"Red";"Green"))</item>
61            </paragraph>
62            <paragraph xml-lang="en-US" id="par_id3146975" role="listitem" l10n="U" oldref="21">The "&amp;" symbol designates the current contents of the <emph>Search for</emph> field. The line must begin with an equal sign, since it is a formula. It is assumed that the cell styles "Red" and "Green" already exist.</paragraph>
63         </listitem>
64         <listitem>
65            <paragraph xml-lang="en-US" id="par_id3149262" role="listitem" l10n="U" oldref="22">Mark the fields <link href="text/shared/01/02100000.xhp" name="Regular expressions"><emph>Regular expressions</emph></link> and <emph>Current selection only</emph>. Click <emph>Find All</emph>.</paragraph>
66            <paragraph xml-lang="en-US" id="par_id3144767" role="listitem" l10n="U" oldref="24">All cells with contents that were included in the selection are now highlighted.</paragraph>
67         </listitem>
68         <listitem>
69            <paragraph xml-lang="en-US" id="par_id3147127" role="listitem" l10n="U" oldref="23">Click<emph/>
70               <item type="menuitem">Replace all</item>.</paragraph>
71         </listitem>
72      </list>
73      <section id="relatedtopics">
74         <embed href="text/scalc/guide/cellstyle_conditional.xhp#cellstyle_conditional"/>
75         <embed href="text/scalc/guide/cellstyle_minusvalue.xhp#cellstyle_minusvalue"/>
76      </section>
77   </body>
78</helpdocument>