<?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>Virtage Devblog &#187; Excel</title>
	<atom:link href="http://devblog.virtage.com/tag/excel/feed/" rel="self" type="application/rss+xml" />
	<link>http://devblog.virtage.com</link>
	<description>Blogs and tutorials mostly on Java client-side (Java SE) and server-side (Java EE) and Ubuntu Linux.</description>
	<lastBuildDate>Sun, 05 Feb 2012 08:43:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>en: Highlight current row in Excel using VBA</title>
		<link>http://devblog.virtage.com/2009/01/en-highlight-current-row-in-excel-using-vba/</link>
		<comments>http://devblog.virtage.com/2009/01/en-highlight-current-row-in-excel-using-vba/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 07:29:58 +0000</pubDate>
		<dc:creator>Libor Jelinek</dc:creator>
				<category><![CDATA[Etc.]]></category>
		<category><![CDATA[Excel]]></category>

		<guid isPermaLink="false">http://devel.virtage.com/?p=31</guid>
		<description><![CDATA[Highlighing currently edited row for better user experience that maybe someday buil-in in Excel, meanwhile you must use Visual Basic for Application code to do this. It&#8217;s very helpful especially in very wide long rows. In this tutorial I will show you how to employ Excel event model to highligh current row. Download the example [...]]]></description>
			<content:encoded><![CDATA[	<p><em>Highlighing currently edited row for better user experience that maybe someday buil-in in Excel, meanwhile you must use Visual Basic for Application code to do this. It&#8217;s very helpful especially in very wide long rows. In this tutorial I will show you how to employ Excel event model to highligh current row.</em></p>

	<p><span id="more-31"></span></p>

	<p><em>Download the <a href="http://devblog.virtage.com/wp-content/uploads/2009/01/book3.xls">example workbook with highlighing current row</a>.</em><br />
<ol>
	<li>Firstly,<strong> format some cell like a highlighted one should looks like</strong> using different background color, font weight, font color, anything you want. Here, cell A4 is formated like highlighted.<br />
<img class="alignnone size-full wp-image-64" title="excelhighlightrow1" src="http://devel.virtage.com/wp-content/uploads/2009/01/excelhighlightrow1.png" alt="excelhighlightrow1" width="703" height="453" /></li>
	<li><strong>Define a new style named „Highlight“. </strong> This style will be used for an entire row.<br />
<ul>
	<li>Select menu item <em>Format / Style</em>.<br />
<img class="alignnone size-full wp-image-65" title="excelhighlightrow2" src="http://devel.virtage.com/wp-content/uploads/2009/01/excelhighlightrow2.png" alt="excelhighlightrow2" width="374" height="234" /></li>
	<li>In <em>Style</em> dialog fill in name „Highligh“, uncheck <em>Number, Alignment </em>and <em>Protection</em> checkboxes.<br />
<img class="alignnone size-full wp-image-66" title="excelhighlightrow3" src="http://devel.virtage.com/wp-content/uploads/2009/01/excelhighlightrow3.png" alt="excelhighlightrow3" width="388" height="256" /></li>
	<li>Click <em>Add</em> button.</li>
	<li>Now we have two styles: Highlight for current row, and Normal for the rest of worksheet.</li><br />
</ul><br />
</li>
	<li><strong>Open <span class="caps">VBA</span> editor</strong> by pressing <em>Alt+F11</em> or <em>Tools / Marco / Visual Basic Editor</em>.</li>
	<li>Create new Worksheet_SelectionChange event handler.<br />
<ul>
	<li>Double-click in left pane to sheet and file where you want to highlight row (e.g. sheet <em>Sheet1 </em>in file <em>Book3.xls</em>)<br />
<img class="alignnone size-full wp-image-67" title="excelhighlightrow4" src="http://devel.virtage.com/wp-content/uploads/2009/01/excelhighlightrow4.png" alt="excelhighlightrow4" width="199" height="304" /></li>
	<li>Then in code editor select <em>Worksheet</em> from Object drop-down box and <em>SelectionChange </em>from Procedure drop-down box.<br />
<img class="alignnone size-full wp-image-68" title="excelhighlightrow5" src="http://devel.virtage.com/wp-content/uploads/2009/01/excelhighlightrow5.png" alt="excelhighlightrow5" width="699" height="322" /></li>
	<li><span class="caps">VBA</span> will create blank <em>Worksheet_SelectionChange</em> procedure acting like SelectionChange event handler.</li><br />
</ul><br />
</li>
	<li><strong>Paste the code. </strong>SelectionChange event will fire everytime you change cell (by arrow key, mouse, click to row/column header). In this case, we want to highlight a row. Paste following source code to the body of handler.</li><br />
</ol></p>


<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #008000;">' Highlight only if selection change was made inside the content range (A2:E50)
</span><span style="color: #8D38C9; font-weight: bold;">If</span> <span style="color: #8D38C9; font-weight: bold;">Not</span> Intersect(Target, Range(<span style="color: #800000;">&quot;A2:E50&quot;</span>)) <span style="color: #8D38C9; font-weight: bold;">Is</span> <span style="color: #00C2FF; font-weight: bold;">Nothing</span> <span style="color: #8D38C9; font-weight: bold;">Then</span>
  <span style="color: #008000;">' Turn off screen updating for better performace
</span>  Application.ScreenUpdating = <span style="color: #00C2FF; font-weight: bold;">False</span>
&nbsp;
  <span style="color: #008000;">' Clear style of content range (A2:E50)
</span>  Range(<span style="color: #800000;">&quot;A2:E50&quot;</span>).Style = <span style="color: #800000;">&quot;Normal&quot;</span>
&nbsp;
  <span style="color: #008000;">' Set highligh style to current row
</span>  <span style="color: #008000;">' (will Target.Row contains current row number)
</span>  Range(<span style="color: #800000;">&quot;A&quot;</span> &amp;amp; Target.Row &amp;amp; <span style="color: #800000;">&quot;:E&quot;</span> &amp;amp; Target.Row).Style = <span style="color: #800000;">&quot;Highlight&quot;</span>
&nbsp;
  <span style="color: #008000;">' Turn on screen updating
</span>  Application.ScreenUpdating = <span style="color: #00C2FF; font-weight: bold;">True</span>
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://devblog.virtage.com/2009/01/en-highlight-current-row-in-excel-using-vba/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

