<?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>Corporate Treasury &#187; Financial modelling</title>
	<atom:link href="http://corporatetreasury.net/index.php/category/financial-modelling/feed/" rel="self" type="application/rss+xml" />
	<link>http://corporatetreasury.net</link>
	<description>No risk, no fun!</description>
	<lastBuildDate>Tue, 27 Jul 2010 10:06:23 +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>Dynamic named range change</title>
		<link>http://corporatetreasury.net/index.php/2008/12/05/test-wp_codebox/</link>
		<comments>http://corporatetreasury.net/index.php/2008/12/05/test-wp_codebox/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 08:31:21 +0000</pubDate>
		<dc:creator>Przemek</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[Financial modelling]]></category>

		<guid isPermaLink="false">http://morsik.net/?p=3</guid>
		<description><![CDATA[Sometimes, in financial modelling in Excel, is very useful to implement changing of named ranges dynamically. E.g. when you're building of matrix of IRRs and margins, which depends on NOI (net operating income) and investment budget and as a result you have matrix with solutions like, "show me all possibilites with IRR &#62; 10% and [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: tahoma,arial,helvetica,sans-serif;">Sometimes, in financial modelling in Excel, is very useful to implement changing of named ranges dynamically. E.g. when you're building of matrix of IRRs and margins, which depends on NOI (net operating income) and investment budget and as a result you have matrix with solutions like, "show me all possibilites with IRR &gt; 10% and margin &gt; 20%. At the end you can receive a function describing all solutions using built-in Linest() function.</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: tahoma,arial,helvetica,sans-serif;">The problem arrise, when you want to play with initial variables like: exchange rate or interest rate which have impact on number of solutions, so we have to be able to add or remove some cells used by Linest().</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: tahoma,arial,helvetica,sans-serif;"><span id="more-16"></span><br />
</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: tahoma,arial,helvetica,sans-serif;">First we need to put named ranges as a argument for our function:</span></span></p>
<blockquote style="text-align: justify;"><p><span style="font-size: small;"><span style="font-family: tahoma,arial,helvetica,sans-serif;">Linest(known_y;known_x)</span></span></p></blockquote>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: tahoma,arial,helvetica,sans-serif;">Then, in the sheet where are initials variables are we have to put following code:</span></span></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p16code3'); return false;">View Code</a> VB</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p163"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p16code3"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Private</span> <span style="color: #000080;">Sub</span> Worksheet_Change(<span style="color: #000080;">ByVal</span> Target <span style="color: #000080;">As</span> Range)
<span style="color: #000080;">If</span> Target.Address = <span style="color: #800000;">&quot;$E$13&quot;</span> <span style="color: #000080;">Or</span> Target.Address = <span style="color: #800000;">&quot;$E$43&quot;</span> <span style="color: #000080;">Then</span>
    LinearRegressionArgsRedefine
<span style="color: #000080;">Else</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
<span style="color: #000080;">Exit</span> <span style="color: #000080;">Sub</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></td></tr></table></div>

<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: tahoma,arial,helvetica,sans-serif;">First sub is checking if our cells with initials variables have changed. If yes, second sub is firing.</span></span></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p16code4'); return false;">View Code</a> VB</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p164"><td class="line_numbers"><pre>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
</pre></td><td class="code" id="p16code4"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Sub</span> LinearRegressionArgsRedefine()
Application.ScreenUpdating = <span style="color: #000080;">False</span>
&nbsp;
ActiveWorkbook.Names(<span style="color: #800000;">&quot;known_y&quot;</span>).Delete
ActiveWorkbook.Names(<span style="color: #800000;">&quot;known_x&quot;</span>).Delete
&nbsp;
<span style="color: #000080;">Dim</span> r <span style="color: #000080;">As</span> Range
<span style="color: #000080;">Dim</span> cell <span style="color: #000080;">As</span> Range
<span style="color: #000080;">Dim</span> wks <span style="color: #000080;">As</span> Worksheet
<span style="color: #000080;">Dim</span> startRow <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span>
&nbsp;
<span style="color: #000080;">Set</span> r = Worksheets(<span style="color: #800000;">&quot;formula&quot;</span>).Range(<span style="color: #800000;">&quot;H8:H34&quot;</span>)
<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> cell <span style="color: #000080;">In</span> r
    <span style="color: #000080;">If</span> cell.Value &amp;lt;&amp;gt; 0 <span style="color: #000080;">Then</span>
        startRow = cell.Row
        <span style="color: #000080;">Dim</span> startY <span style="color: #000080;">As</span> <span style="color: #000080;">Variant</span>
        <span style="color: #000080;">Dim</span> stopY <span style="color: #000080;">As</span> <span style="color: #000080;">Variant</span>
        <span style="color: #000080;">Dim</span> startX <span style="color: #000080;">As</span> <span style="color: #000080;">Variant</span>
        <span style="color: #000080;">Dim</span> stopX <span style="color: #000080;">As</span> <span style="color: #000080;">Variant</span>
        startY = <span style="color: #800000;">&quot;$H$&quot;</span> &amp;amp; startRow
        stopY = <span style="color: #800000;">&quot;$H$34&quot;</span>
        startX = <span style="color: #800000;">&quot;$G$&quot;</span> &amp;amp; startRow
        stopX = <span style="color: #800000;">&quot;$G$34&quot;</span>
        RangeY = <span style="color: #800000;">&quot;=formula!&quot;</span> &amp;amp; startY &amp;amp; <span style="color: #800000;">&quot;:&quot;</span> &amp;amp; stopY
        RangeX = <span style="color: #800000;">&quot;=formula!&quot;</span> &amp;amp; startX &amp;amp; <span style="color: #800000;">&quot;:&quot;</span> &amp;amp; stopX
&nbsp;
    ActiveWorkbook.Names.Add Name:=<span style="color: #800000;">&quot;known_y&quot;</span>, RefersTo:=<span style="color: #000080;">CStr</span>(RangeY)
    ActiveWorkbook.Names.Add Name:=<span style="color: #800000;">&quot;known_x&quot;</span>, RefersTo:=<span style="color: #000080;">CStr</span>(RangeX)
&nbsp;
<span style="color: #000080;">Exit</span> <span style="color: #000080;">For</span>
<span style="color: #000080;">Else</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
<span style="color: #000080;">Next</span>
Application.ScreenUpdating = <span style="color: #000080;">True</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></td></tr></table></div>

<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: tahoma,arial,helvetica,sans-serif;">It removes now outdated named ranges and checking which cells have got solutions which suits us and creates updated named ranges. Linest function is recalculating accordingly. That's all.</span></span></p>
<img src="http://corporatetreasury.net/?ak_action=api_record_view&id=16&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://corporatetreasury.net/index.php/2008/12/05/test-wp_codebox/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

