summaryrefslogtreecommitdiff
path: root/source/text/scalc/guide/cellstyle_by_formula.xhp
blob: 197f46ab453dbccbc5b153974435d89f475ef7a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?xml version="1.0" encoding="UTF-8"?>
<helpdocument version="1.0">
<!--
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->

<meta>
  <topic id="textscalcguidecellstyle_by_formulaxml" indexer="include" status="PUBLISH">
    <title id="tit" xml-lang="en-US">Assigning Formats by Formula</title>
    <filename>/text/scalc/guide/cellstyle_by_formula.xhp</filename>
  </topic>
</meta>

<body>

<bookmark xml-lang="en-US" branch="index" id="bm_id3145673">
  <bookmark_value>formats; assigning by formulas</bookmark_value>
  <bookmark_value>cell formats; assigning by formulas</bookmark_value>
  <bookmark_value>STYLE function example</bookmark_value>
  <bookmark_value>cell styles;assigning by formulas</bookmark_value>
  <bookmark_value>formulas;assigning cell formats</bookmark_value>
</bookmark>
<comment>mw deleted "applying;"</comment>

<paragraph id="hd_id3145673" role="heading" level="1" xml-lang="en-US"><variable id="cellstyle_by_formula"><link href="text/scalc/guide/cellstyle_by_formula.xhp">Assigning Formats by Formula</link></variable></paragraph>
<paragraph id="par_id3150275" role="paragraph" xml-lang="en-US">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>
<paragraph id="par_id3151385" role="paragraph" xml-lang="en-US">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>

<list type="ordered">
  <listitem>
    <paragraph id="par_id3149456" role="listitem" xml-lang="en-US">Select all the desired cells.</paragraph>
  </listitem>
  <listitem>
    <paragraph id="par_id3148797" role="listitem" xml-lang="en-US">Select the menu command <emph>Edit - Find &amp; Replace</emph>.</paragraph>
  </listitem>
  <listitem>
    <paragraph id="par_id3150767" role="listitem" xml-lang="en-US">For the <item type="menuitem">Find</item> term, enter: .<item type="literal">*</item></paragraph>
    <paragraph id="par_id3153770" role="listitem" xml-lang="en-US">".*" is a regular expression that designates the contents of the current cell.</paragraph>
  </listitem>
  <listitem>
    <paragraph id="par_id3153143" role="listitem" xml-lang="en-US">Enter the following formula in the <item type="menuitem">Replace</item> field: <item type="literal">=&amp;+STYLE(IF(CURRENT()&gt;3;"Red";"Green"))</item></paragraph>
    <paragraph id="par_id3146975" role="listitem" xml-lang="en-US">The "&amp;" symbol designates the current contents of the <emph>Find</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>
  </listitem>
  <listitem>
    <paragraph id="par_id3149262" role="listitem" xml-lang="en-US">Mark the fields <link href="text/shared/01/02100000.xhp"><emph>Regular expressions</emph></link> and <emph>Current selection only</emph>. Click <emph>Find All</emph>.</paragraph>
    <paragraph id="par_id3144767" role="listitem" xml-lang="en-US">All cells with contents that were included in the selection are now highlighted.</paragraph>
  </listitem>
  <listitem>
    <paragraph id="par_id3147127" role="listitem" xml-lang="en-US">Click <item type="menuitem">Replace all</item>.</paragraph>
  </listitem>
</list>

<section id="relatedtopics">
<embed href="text/scalc/guide/cellstyle_conditional.xhp#cellstyle_conditional"/>
<embed href="text/scalc/guide/cellstyle_minusvalue.xhp#cellstyle_minusvalue"/>
</section>
</body>

</helpdocument>