<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Digital-Traffic.net &#187; conditional formatting</title>
	<atom:link href="http://digital-traffic.net/tag/conditional-formatting/feed/" rel="self" type="application/rss+xml" />
	<link>http://digital-traffic.net</link>
	<description>Public thoughts of a network administrator</description>
	<lastBuildDate>Sun, 31 Jan 2010 21:02:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Formatting byte values in Excel 2007</title>
		<link>http://digital-traffic.net/technology/formatting-byte-values-in-excel-2007/</link>
		<comments>http://digital-traffic.net/technology/formatting-byte-values-in-excel-2007/#comments</comments>
		<pubDate>Thu, 21 May 2009 02:44:51 +0000</pubDate>
		<dc:creator>Brian Shacklett</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[conditional formatting]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[formatting]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[spreadsheet]]></category>

		<guid isPermaLink="false">http://digital-traffic.net/?p=132</guid>
		<description><![CDATA[<p>
I was given a project, recently, that involved creating a spreadsheet to list storage capacities and free space. One thing I wasn't sure of, was how to format the values&#8230;
</p>
<p>
&#8230;After thinking about it for a while, I decided to look into Excel's conditional formatting feature. There are premade rules for changing the cell color, etc., but it turns out that it's capable of quite a bit more&#8230;
</p>]]></description>
			<content:encoded><![CDATA[<p>
I was given a project, recently, that involved creating a spreadsheet to list storage capacities and free space. One thing I wasn&#8217;t sure of, was how to format the values.
</p>
<p>
A bit of searching on the internet for formatting KB MB, etc. came up with a <a href="http://www.eggheadcafe.com/conversation.aspx?messageid=33805458&#038;threadid=33805450">post</a> by Ajay on <a href="http://www.eggheadcafe.com">http://www.eggheadcafe.com</a> which suggested pasting the following code into the current worksheet&#8217;s private module:
</p>
<pre class="brush: vb">
Private Sub Worksh5eet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range(&quot;C:C&quot;)) Is Nothing Then
        If Target.Value &lt; 1000 Then
            Target.NumberFormat = &quot;0 \B&quot;
        ElseIf Target.Value &lt; 999500 Then
            Target.NumberFormat = &quot;0.000, \K\B&quot;
        ElseIf Target.Value &lt; 999500000 Then
            Target.NumberFormat = &quot;0.000,, \M\B&quot;
        ElseIf Target.Value &lt; 999500000000# Then
            Target.NumberFormat = &quot;0.000,,, \G\B&quot;
        Else
            Target.NumberFormat = &quot;0.000,,,, \T\B&quot;
        End If
    End If
End Sub
</pre>
<p>
I had some trouble with the macro and eventually abandoned it, but it did give me some ideas. The actual formats were good and I ended up using them later. The criteria for setting the formatting was spot on as well. After thinking about it for a while, I decided to look into Excel&#8217;s conditional formatting feature. There are premade rules for changing the cell color, etc., but it turns out that it&#8217;s capable of quite a bit more.
</p>
<p><span id="more-132"></span></p>
<h3>Setting up formatting rules</h3>
<p>
Conditional formatting is based on sets of rules which are stored in each worksheet. To create a new rule, go to <code class="input">Home &gt; Styles &gt; Conditional Formatting &gt; Manage Rules...</code>. Click <code class="input">New Rule...</code> and select &quot;Format only cells that contain&quot;. Select &quot;Cell Value&quot;, &quot;less than&quot; and enter &quot;1000&quot; for the value.
</p>
<p><img src="http://digital-traffic.net/wp-content/uploads/2009/05/new-rule.png" alt="New Rule... dialog" title="New Rule... dialog" width="520" height="91" class="size-full wp-image-150" /></p>
<p>
Once the condition is set, click <code class="input">Format...</code> set the formatting. In this case we are formatting values that are less than 1KB, so we&#8217;ll want to set a custom format of &quot;0 \B&quot;
</p>
<p><img src="http://digital-traffic.net/wp-content/uploads/2009/05/format-bytes.png" alt="Format Cells dialog" title="Format Cells dialog" width="525" height="340" class="size-full wp-image-157" /></p>
<p>
Make a few more rules for kilobytes, megabytes, etc. You&#8217;ll probably want to show a couple of decimal places for the larger numbers. Add a comma for each order of magnitude as you&#8217;ll be showing a suffix rather than the extra zeros. You should end up with formats similar to this:</p>
<pre>
0 \B
0.00, \K\B
0.00,, \M\B
0.00,,, \G\B
</pre>
</ul>
<h3>Applying the rules</h3>
<p>
Once you finish creating your rules, you&#8217;ll be brought back to the Conditional Formatting Rules Manager. You&#8217;ll probably notice that &#8220;Current Selection&#8221; is selected at the top of the dialog. Change this over to &#8220;This Worksheet&#8221; for better control. Although it shouldn&#8217;t matter too much, I&#8217;d recommend ordering the rules from smallest to largest. This should prevent potentially funky behavior if a cell&#8217;s value should fall on a boundary between rules. I also suggest leaving &#8220;Stop If True&#8221; unchecked to let the latter rule win.
</p>
<p>
You&#8217;ll notice that there is an &#8220;Applies To&#8221; box. This is where we select which cells will be affected by the rules. Click the button and make your selections. Cells in each selection should be adjacent to avoid complications. Use the ctrl key to select multiple ranges. Once you&#8217;ve made your selection, click the button again and copy the contents of the box to the other rules and you&#8217;re done.
</p>
<h3>Other thoughts</h3>
<p>
This approach works based on multiples of 1000 instead of 1024. Setting the criteria to look for the correct boundaries is easy enough by specifying &quot;Cell Value between =Power(2,10) and =Power(2,20)&quot;, but I haven&#8217;t yet found a way to get Excel to see 1024B as 1KB as opposed to 1.024KB. Any input on this would be quite welcome.
</p>
<p>
This approach should work well for formatting any units that are base 10; metric units, for instance. The base unit can be chosen arbitrarily, so it&#8217;s really quite wide open.</p>
]]></content:encoded>
			<wfw:commentRss>http://digital-traffic.net/technology/formatting-byte-values-in-excel-2007/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
