xref: /trunk/main/helpcontent2/source/text/scalc/guide/cellstyle_by_formula.xhp (revision eac72b6ce8e8be3e6514ba0a595ba52bccea36cf)
1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2cdf0e10cSrcweir
3ce44d6c1SAndrew Rist<!--***********************************************************
4cdf0e10cSrcweir *
5ce44d6c1SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
6ce44d6c1SAndrew Rist * or more contributor license agreements.  See the NOTICE file
7ce44d6c1SAndrew Rist * distributed with this work for additional information
8ce44d6c1SAndrew Rist * regarding copyright ownership.  The ASF licenses this file
9ce44d6c1SAndrew Rist * to you under the Apache License, Version 2.0 (the
10ce44d6c1SAndrew Rist * "License"); you may not use this file except in compliance
11ce44d6c1SAndrew Rist * with the License.  You may obtain a copy of the License at
12cdf0e10cSrcweir *
13ce44d6c1SAndrew Rist *   http://www.apache.org/licenses/LICENSE-2.0
14cdf0e10cSrcweir *
15ce44d6c1SAndrew Rist * Unless required by applicable law or agreed to in writing,
16ce44d6c1SAndrew Rist * software distributed under the License is distributed on an
17ce44d6c1SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18ce44d6c1SAndrew Rist * KIND, either express or implied.  See the License for the
19ce44d6c1SAndrew Rist * specific language governing permissions and limitations
20ce44d6c1SAndrew Rist * under the License.
21cdf0e10cSrcweir *
22ce44d6c1SAndrew Rist ***********************************************************-->
23ce44d6c1SAndrew Rist
2494e420e4Smseidel<helpdocument version="1.0">
25cdf0e10cSrcweir<meta>
26cdf0e10cSrcweir<topic id="textscalcguidecellstyle_by_formulaxml" indexer="include" status="PUBLISH">
27cdf0e10cSrcweir<title xml-lang="en-US" id="tit">Assigning Formats by Formula</title>
28cdf0e10cSrcweir<filename>/text/scalc/guide/cellstyle_by_formula.xhp</filename>
29cdf0e10cSrcweir</topic>
30cdf0e10cSrcweir</meta>
31cdf0e10cSrcweir<body>
3294e420e4Smseidel<bookmark xml-lang="en-US" branch="index" id="bm_id3145673">
3394e420e4Smseidel<bookmark_value>formats; assigning by formulas</bookmark_value>
34cdf0e10cSrcweir<bookmark_value>cell formats; assigning by formulas</bookmark_value>
35cdf0e10cSrcweir<bookmark_value>STYLE function example</bookmark_value>
36cdf0e10cSrcweir<bookmark_value>cell styles;assigning by formulas</bookmark_value>
37cdf0e10cSrcweir<bookmark_value>formulas;assigning cell formats</bookmark_value>
38cdf0e10cSrcweir</bookmark><comment>mw deleted "applying;"</comment>
39*9900b3e2Smseidel<paragraph xml-lang="en-US" id="hd_id3145673" role="heading" level="1" l10n="U"><variable id="cellstyle_by_formula"><link href="text/scalc/guide/cellstyle_by_formula.xhp" name="Assigning Formats by Formula">Assigning Formats by Formula</link>
40cdf0e10cSrcweir</variable></paragraph>
41*9900b3e2Smseidel<paragraph xml-lang="en-US" id="par_id3150275" role="paragraph" l10n="CHG">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>
42*9900b3e2Smseidel<paragraph xml-lang="en-US" id="par_id3151385" role="paragraph" l10n="U">If you would like to apply a formula to all cells in a selected area, you can use the <item type="menuitem">Find &amp; Replace</item> dialog.</paragraph>
43cdf0e10cSrcweir<list type="ordered">
44cdf0e10cSrcweir<listitem>
45*9900b3e2Smseidel<paragraph xml-lang="en-US" id="par_id3149456" role="listitem" l10n="U">Select all the desired cells.</paragraph>
46cdf0e10cSrcweir</listitem>
47cdf0e10cSrcweir<listitem>
48*9900b3e2Smseidel<paragraph xml-lang="en-US" id="par_id3148797" role="listitem" l10n="U">Select the menu command <emph>Edit - Find &amp; Replace</emph>.</paragraph>
49cdf0e10cSrcweir</listitem>
50cdf0e10cSrcweir<listitem>
51*9900b3e2Smseidel<paragraph xml-lang="en-US" id="par_id3150767" role="listitem" l10n="U">For the <item type="menuitem">Search for</item> term, enter: .<item type="literal">*</item>
52cdf0e10cSrcweir</paragraph>
53*9900b3e2Smseidel<paragraph xml-lang="en-US" id="par_id3153770" role="listitem" l10n="U">".*" is a regular expression that designates the contents of the current cell.</paragraph>
54cdf0e10cSrcweir</listitem>
55cdf0e10cSrcweir<listitem>
56*9900b3e2Smseidel<paragraph xml-lang="en-US" id="par_id3153143" role="listitem" l10n="U">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>
57cdf0e10cSrcweir</paragraph>
58*9900b3e2Smseidel<paragraph xml-lang="en-US" id="par_id3146975" role="listitem" l10n="U">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>
59cdf0e10cSrcweir</listitem>
60cdf0e10cSrcweir<listitem>
61*9900b3e2Smseidel<paragraph xml-lang="en-US" id="par_id3149262" role="listitem" l10n="U">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>
62*9900b3e2Smseidel<paragraph xml-lang="en-US" id="par_id3144767" role="listitem" l10n="U">All cells with contents that were included in the selection are now highlighted.</paragraph>
63cdf0e10cSrcweir</listitem>
64cdf0e10cSrcweir<listitem>
65*9900b3e2Smseidel<paragraph xml-lang="en-US" id="par_id3147127" role="listitem" l10n="U">Click <item type="menuitem">Replace all</item>.</paragraph>
66cdf0e10cSrcweir</listitem>
67cdf0e10cSrcweir</list>
68cdf0e10cSrcweir<section id="relatedtopics">
69cdf0e10cSrcweir<embed href="text/scalc/guide/cellstyle_conditional.xhp#cellstyle_conditional"/>
70cdf0e10cSrcweir<embed href="text/scalc/guide/cellstyle_minusvalue.xhp#cellstyle_minusvalue"/>
71cdf0e10cSrcweir</section>
72cdf0e10cSrcweir</body>
73cdf0e10cSrcweir</helpdocument>
74