<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Ugly Formulas</title>
	<atom:link href="http://www.dailydoseofexcel.com/archives/2004/06/23/ugly-formulas/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dailydoseofexcel.com/archives/2004/06/23/ugly-formulas/</link>
	<description>Daily posts of Excel tips…and other stuff</description>
	<lastBuildDate>Mon, 06 Feb 2012 18:39:56 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Ben</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/23/ugly-formulas/#comment-67254</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Tue, 25 Oct 2011 04:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=650#comment-67254</guid>
		<description>&lt;p&gt;Couldn&#039;t help but throw my hat into the ring here...&lt;/p&gt;
&lt;p&gt;=IF(OR($B2=&quot;DS&quot;,$B2=&quot;Manual&quot;)=TRUE,IF($B2=&quot;DS&quot;,IF($C2=&quot;Price&quot;,OFFSET(&#039;DS Data&#039;!D$1,MATCH($D2,&#039;DS Data&#039;!$B$2:$B$1048576,0),0)/OFFSET(&#039;DS Data&#039;!C$1,MATCH($D2,&#039;DS Data&#039;!$B$2:$B$1048576,0),0)-1,OFFSET(&#039;DS Data&#039;!C$1,MATCH($D2,&#039;DS Data&#039;!$B$2:$B$1048576,0),0)/1200),IF($C2=&quot;Price&quot;,OFFSET(&#039;Manual Data&#039;!$A$2,MATCH(E$1,&#039;Manual Data&#039;!$A$3:$A$1048576,0),MATCH($A2,&#039;Manual Data&#039;!$B$1:$XFD$1,0))/OFFSET(&#039;Manual Data&#039;!$A$2,MATCH(E$1,&#039;Manual Data&#039;!$A$3:$A$1048576,0)-1,MATCH($A2,&#039;Manual Data&#039;!$B$1:$XFD$1,0))-1,OFFSET(&#039;Manual Data&#039;!$A$2,MATCH(E$1,&#039;Manual Data&#039;!$A$3:$A$1048576,0)-1,MATCH($A2,&#039;Manual Data&#039;!$B$1:$XFD$1,0))/1200)),ERROR.TYPE(1))&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Couldn&#8217;t help but throw my hat into the ring here&#8230;</p>
<p>=IF(OR($B2=&#8221;DS&#8221;,$B2=&#8221;Manual&#8221;)=TRUE,IF($B2=&#8221;DS&#8221;,IF($C2=&#8221;Price&#8221;,OFFSET(&#8216;DS Data&#8217;!D$1,MATCH($D2,&#8217;DS Data&#8217;!$B$2:$B$1048576,0),0)/OFFSET(&#8216;DS Data&#8217;!C$1,MATCH($D2,&#8217;DS Data&#8217;!$B$2:$B$1048576,0),0)-1,OFFSET(&#8216;DS Data&#8217;!C$1,MATCH($D2,&#8217;DS Data&#8217;!$B$2:$B$1048576,0),0)/1200),IF($C2=&#8221;Price&#8221;,OFFSET(&#8216;Manual Data&#8217;!$A$2,MATCH(E$1,&#8217;Manual Data&#8217;!$A$3:$A$1048576,0),MATCH($A2,&#8217;Manual Data&#8217;!$B$1:$XFD$1,0))/OFFSET(&#8216;Manual Data&#8217;!$A$2,MATCH(E$1,&#8217;Manual Data&#8217;!$A$3:$A$1048576,0)-1,MATCH($A2,&#8217;Manual Data&#8217;!$B$1:$XFD$1,0))-1,OFFSET(&#8216;Manual Data&#8217;!$A$2,MATCH(E$1,&#8217;Manual Data&#8217;!$A$3:$A$1048576,0)-1,MATCH($A2,&#8217;Manual Data&#8217;!$B$1:$XFD$1,0))/1200)),ERROR.TYPE(1))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lori</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/23/ugly-formulas/#comment-43465</link>
		<dc:creator>Lori</dc:creator>
		<pubDate>Thu, 21 Jan 2010 18:05:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=650#comment-43465</guid>
		<description>&lt;p&gt;Rick - yes, the formula finds the closest selection of values to the given target value. It returns TRUE next to each value to include in the sum. The result could be larger or smaller than the target. &lt;/p&gt;
&lt;p&gt;For 16 values, there are 2^16=65536 combinations, equal to the number of rows in Excel 2003. Each combination is tested by calculating the difference (scaled up and rounded) and then adding on the position index. The results are passed to SMALL(.,B1), which returns the smallest combination of difference and position index. Changing B1 to 2 returns the next smallest combination etc.&lt;/p&gt;
&lt;p&gt;In the Excel 2010 beta this more flexible (though even more incoherent!) version seems to work, which extends to up to 20 test values.&lt;/p&gt;
&lt;p&gt;=MOD(MOD(SMALL(ABS(ROUND((MMULT(INT(MOD(ROW(A1:INDEX(A:A,2^ROWS(A2:A17)))&lt;br&gt;
/2^TRANSPOSE((ROW(A2:A17)-ROW(A2))),2)),A2:A17)-A1)*10^9,-7))+&lt;br&gt;
ROW(A1:INDEX(A:A,2^ROWS(A2:A17))),B1),10^7)/2^(ROW(A2:A17)-ROW(A2)),2)&gt;=1&lt;/p&gt;
&lt;p&gt;The MMULT function works for larger ranges now apparently, don&#039;t know about Excel 2007?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Rick &#8211; yes, the formula finds the closest selection of values to the given target value. It returns TRUE next to each value to include in the sum. The result could be larger or smaller than the target. </p>
<p>For 16 values, there are 2^16=65536 combinations, equal to the number of rows in Excel 2003. Each combination is tested by calculating the difference (scaled up and rounded) and then adding on the position index. The results are passed to SMALL(.,B1), which returns the smallest combination of difference and position index. Changing B1 to 2 returns the next smallest combination etc.</p>
<p>In the Excel 2010 beta this more flexible (though even more incoherent!) version seems to work, which extends to up to 20 test values.</p>
<p>=MOD(MOD(SMALL(ABS(ROUND((MMULT(INT(MOD(ROW(A1:INDEX(A:A,2^ROWS(A2:A17)))<br />
/2^TRANSPOSE((ROW(A2:A17)-ROW(A2))),2)),A2:A17)-A1)*10^9,-7))+<br />
ROW(A1:INDEX(A:A,2^ROWS(A2:A17))),B1),10^7)/2^(ROW(A2:A17)-ROW(A2)),2)&gt;=1</p>
<p>The MMULT function works for larger ranges now apparently, don&#8217;t know about Excel 2007?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lori`</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/23/ugly-formulas/#comment-43464</link>
		<dc:creator>Lori`</dc:creator>
		<pubDate>Thu, 21 Jan 2010 17:50:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=650#comment-43464</guid>
		<description>&lt;p&gt;Rick - yes, the formula finds the closest selection of values to the given target value. It returns TRUE next to each value to include in the sum. The result could be larger or smaller than the target. &lt;/p&gt;
&lt;p&gt;For 16 values, there are 2^16=65536 combinations, equal to the number of rows in Excel 2003. Each combination is tested by calculating the difference (scaled up and rounded) and then adding on the position index. The results are passed to SMALL(.,B1), which returns the smallest combination of difference and position index. Changing B1 to 2 returns the next smallest combination etc.&lt;/p&gt;
&lt;p&gt;In the Excel 2010 beta this more flexible (though even more incoherent!) version seems to work, which extends to up to 20 test values.&lt;/p&gt;
&lt;p&gt;=MOD(MOD(SMALL(ABS(ROUND((MMULT(INT(MOD(ROW(A1:INDEX(A:A,2^ROWS(A2:A17)))&lt;br&gt;
/2^TRANSPOSE((ROW(A2:A17)-ROW(A2))),2)),A2:A17)-A1)*10^9,-7))+&lt;br&gt;
ROW(A1:INDEX(A:A,2^ROWS(A2:A17))),B1),10^7)/2^(ROW(A2:A17)-ROW(A2)),2)&gt;=1&lt;/p&gt;
&lt;p&gt;The MMULT function works for larger ranges now apparently, don&#039;t know about Excel 2007?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Rick &#8211; yes, the formula finds the closest selection of values to the given target value. It returns TRUE next to each value to include in the sum. The result could be larger or smaller than the target. </p>
<p>For 16 values, there are 2^16=65536 combinations, equal to the number of rows in Excel 2003. Each combination is tested by calculating the difference (scaled up and rounded) and then adding on the position index. The results are passed to SMALL(.,B1), which returns the smallest combination of difference and position index. Changing B1 to 2 returns the next smallest combination etc.</p>
<p>In the Excel 2010 beta this more flexible (though even more incoherent!) version seems to work, which extends to up to 20 test values.</p>
<p>=MOD(MOD(SMALL(ABS(ROUND((MMULT(INT(MOD(ROW(A1:INDEX(A:A,2^ROWS(A2:A17)))<br />
/2^TRANSPOSE((ROW(A2:A17)-ROW(A2))),2)),A2:A17)-A1)*10^9,-7))+<br />
ROW(A1:INDEX(A:A,2^ROWS(A2:A17))),B1),10^7)/2^(ROW(A2:A17)-ROW(A2)),2)&gt;=1</p>
<p>The MMULT function works for larger ranges now apparently, don&#8217;t know about Excel 2007?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Rothstein (MVP - Excel)</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/23/ugly-formulas/#comment-43453</link>
		<dc:creator>Rick Rothstein (MVP - Excel)</dc:creator>
		<pubDate>Wed, 20 Jan 2010 19:38:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=650#comment-43453</guid>
		<description>&lt;p&gt;@Lori&lt;/p&gt;
&lt;p&gt;Can you explain in a little more detail what your formula is calculating? It looks like it is identifying the values in A2:A17 that, when added together, will total up to (could be less), but no more than, the target value... if that is the case, then what is the value in B1 for/doing?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@Lori</p>
<p>Can you explain in a little more detail what your formula is calculating? It looks like it is identifying the values in A2:A17 that, when added together, will total up to (could be less), but no more than, the target value&#8230; if that is the case, then what is the value in B1 for/doing?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lori</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/23/ugly-formulas/#comment-43452</link>
		<dc:creator>Lori</dc:creator>
		<pubDate>Wed, 20 Jan 2010 17:52:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=650#comment-43452</guid>
		<description>&lt;p&gt;I like this array formula for finding cells that sum to a target value.&lt;br&gt;
It returns TRUE or FALSE next to each value to include in the sum.&lt;/p&gt;
&lt;p&gt;=MOD(MOD(SMALL(ABS(ROUND((&lt;br&gt;
(MOD(ROW(A:A)/2^0,2)&gt;=1)*A2+&lt;br&gt;
(MOD(ROW(A:A)/2^1,2)&gt;=1)*A3+&lt;br&gt;
(MOD(ROW(A:A)/2^2,2)&gt;=1)*A4+&lt;br&gt;
(MOD(ROW(A:A)/2^3,2)&gt;=1)*A5+&lt;br&gt;
(MOD(ROW(A:A)/2^4,2)&gt;=1)*A6+&lt;br&gt;
(MOD(ROW(A:A)/2^5,2)&gt;=1)*A7+&lt;br&gt;
(MOD(ROW(A:A)/2^6,2)&gt;=1)*A8+&lt;br&gt;
(MOD(ROW(A:A)/2^7,2)&gt;=1)*A9+&lt;br&gt;
(MOD(ROW(A:A)/2^8,2)&gt;=1)*A10+&lt;br&gt;
(MOD(ROW(A:A)/2^9,2)&gt;=1)*A11+&lt;br&gt;
(MOD(ROW(A:A)/2^10,2)&gt;=1)*A12+&lt;br&gt;
(MOD(ROW(A:A)/2^11,2)&gt;=1)*A13+&lt;br&gt;
(MOD(ROW(A:A)/2^12,2)&gt;=1)*A14+&lt;br&gt;
(MOD(ROW(A:A)/2^13,2)&gt;=1)*A15+&lt;br&gt;
(MOD(ROW(A:A)/2^14,2)&gt;=1)*A16+&lt;br&gt;
(MOD(ROW(A:A)/2^15,2)&gt;=1)*A17&lt;br&gt;
-A1)*10^8,-6))+ROW(A:A),B1),10^6)/2&lt;br&gt;
^(ROW(A2:A17)-ROW(A2)),2)&gt;=1&lt;/p&gt;
&lt;p&gt;Put a target value in A1, values to sum in A2:A17, and B1=1.&lt;br&gt;
Select B2:B17 and array-enter this formula with {Ctrl+Shift+Enter}.&lt;/p&gt;
&lt;p&gt;It takes a few seconds to run, you can try B1=2,3,.. for other solutions.&lt;br&gt;
Two decimal places accuracy is assumed.&lt;/p&gt;
&lt;p&gt;I don&#039;t think it&#039;s possible to do in many less characters than this (568).&lt;br&gt;
It could be extended to up to 20 values in Excel 2007+ (~690). lhm&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I like this array formula for finding cells that sum to a target value.<br />
It returns TRUE or FALSE next to each value to include in the sum.</p>
<p>=MOD(MOD(SMALL(ABS(ROUND((<br />
(MOD(ROW(A:A)/2^0,2)&gt;=1)*A2+<br />
(MOD(ROW(A:A)/2^1,2)&gt;=1)*A3+<br />
(MOD(ROW(A:A)/2^2,2)&gt;=1)*A4+<br />
(MOD(ROW(A:A)/2^3,2)&gt;=1)*A5+<br />
(MOD(ROW(A:A)/2^4,2)&gt;=1)*A6+<br />
(MOD(ROW(A:A)/2^5,2)&gt;=1)*A7+<br />
(MOD(ROW(A:A)/2^6,2)&gt;=1)*A8+<br />
(MOD(ROW(A:A)/2^7,2)&gt;=1)*A9+<br />
(MOD(ROW(A:A)/2^8,2)&gt;=1)*A10+<br />
(MOD(ROW(A:A)/2^9,2)&gt;=1)*A11+<br />
(MOD(ROW(A:A)/2^10,2)&gt;=1)*A12+<br />
(MOD(ROW(A:A)/2^11,2)&gt;=1)*A13+<br />
(MOD(ROW(A:A)/2^12,2)&gt;=1)*A14+<br />
(MOD(ROW(A:A)/2^13,2)&gt;=1)*A15+<br />
(MOD(ROW(A:A)/2^14,2)&gt;=1)*A16+<br />
(MOD(ROW(A:A)/2^15,2)&gt;=1)*A17<br />
-A1)*10^8,-6))+ROW(A:A),B1),10^6)/2<br />
^(ROW(A2:A17)-ROW(A2)),2)&gt;=1</p>
<p>Put a target value in A1, values to sum in A2:A17, and B1=1.<br />
Select B2:B17 and array-enter this formula with {Ctrl+Shift+Enter}.</p>
<p>It takes a few seconds to run, you can try B1=2,3,.. for other solutions.<br />
Two decimal places accuracy is assumed.</p>
<p>I don&#8217;t think it&#8217;s possible to do in many less characters than this (568).<br />
It could be extended to up to 20 values in Excel 2007+ (~690). lhm</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hui...</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/23/ugly-formulas/#comment-43450</link>
		<dc:creator>Hui...</dc:creator>
		<pubDate>Wed, 20 Jan 2010 15:34:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=650#comment-43450</guid>
		<description>&lt;p&gt;I wonder what formula will overload or break these comment boxes and yet still do something useful in Excel ?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I wonder what formula will overload or break these comment boxes and yet still do something useful in Excel ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hui...</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/23/ugly-formulas/#comment-43449</link>
		<dc:creator>Hui...</dc:creator>
		<pubDate>Wed, 20 Jan 2010 15:32:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=650#comment-43449</guid>
		<description>&lt;p&gt;I wrote this over at PHD a few weeks ago&lt;/p&gt;
&lt;p&gt;=+TREND(OFFSET($J$6,+MATCH($C7,$J$7:$J$16,1),+MATCH($D7,OFFSET($K$6:$P$6,MATCH($C7,$J$7:$J$16,1)-1,0)),1,2),OFFSET($J$6,+MATCH($C7,$J$7:$J$16,1)-1,+MATCH($D7,OFFSET($K$6:$P$6,MATCH($C7,$J$7:$J$16,1)-1,0)),1,2),$D7)&lt;/p&gt;
&lt;p&gt;Noting that it isn&#039;t padded out with page names, yet !&lt;/p&gt;
&lt;p&gt;It calculates a new Y value for a given X value between a set of X and Y Co-ordinates in an Array which can be in different locations based on 2 other variables (I think that&#039;s what it did)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I wrote this over at PHD a few weeks ago</p>
<p>=+TREND(OFFSET($J$6,+MATCH($C7,$J$7:$J$16,1),+MATCH($D7,OFFSET($K$6:$P$6,MATCH($C7,$J$7:$J$16,1)-1,0)),1,2),OFFSET($J$6,+MATCH($C7,$J$7:$J$16,1)-1,+MATCH($D7,OFFSET($K$6:$P$6,MATCH($C7,$J$7:$J$16,1)-1,0)),1,2),$D7)</p>
<p>Noting that it isn&#8217;t padded out with page names, yet !</p>
<p>It calculates a new Y value for a given X value between a set of X and Y Co-ordinates in an Array which can be in different locations based on 2 other variables (I think that&#8217;s what it did)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The Angler</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/23/ugly-formulas/#comment-43435</link>
		<dc:creator>The Angler</dc:creator>
		<pubDate>Tue, 19 Jan 2010 14:32:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=650#comment-43435</guid>
		<description>&lt;p&gt;Only just happened on this site - how about this bad boy:&lt;/p&gt;
&lt;p&gt;=IF(OR(Main!D77=Options!$F$14,Main!D77=Options!$F$15,Main!D77=Options!$F$16,Main!D77=Options!$F$17,Main!D77=Options!$F$18,Main!D77=Options!$F$19),0,IF(Main!D77?&quot;,SUM(VALUE(LEFT(Main!D77,FIND(Options!$F$11,Main!D77)-1))*256,IF(Options!$D$7=&quot;Y&quot;,VALUE(MID(Main!D77,FIND(Options!$F$11,Main!D77,1)+1,FIND(Options!$F$11,(SUBSTITUTE(Main!D77,Options!$F$11,&quot;X&quot;,1)))-FIND(Options!$F$11,Main!D77,1)-1))*16,VALUE(RIGHT(Main!D77,LEN(Main!D77)-FIND(Options!$F$11,Main!D77)))*16),IF(Options!$D$7=&quot;Y&quot;,RIGHT(Main!D77,LEN(Main!D77)-FIND(Options!$F$11,(SUBSTITUTE(Main!D77,Options!$F$11,&quot;X&quot;,1)),1)),0)),0))&lt;/p&gt;
&lt;p&gt;I wrote it as part of an angling match result calculator. The actual spreadsheet contains this formula in 50 rows x 50 columns.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Only just happened on this site &#8211; how about this bad boy:</p>
<p>=IF(OR(Main!D77=Options!$F$14,Main!D77=Options!$F$15,Main!D77=Options!$F$16,Main!D77=Options!$F$17,Main!D77=Options!$F$18,Main!D77=Options!$F$19),0,IF(Main!D77?&#8221;,SUM(VALUE(LEFT(Main!D77,FIND(Options!$F$11,Main!D77)-1))*256,IF(Options!$D$7=&#8221;Y&#8221;,VALUE(MID(Main!D77,FIND(Options!$F$11,Main!D77,1)+1,FIND(Options!$F$11,(SUBSTITUTE(Main!D77,Options!$F$11,&#8221;X&#8221;,1)))-FIND(Options!$F$11,Main!D77,1)-1))*16,VALUE(RIGHT(Main!D77,LEN(Main!D77)-FIND(Options!$F$11,Main!D77)))*16),IF(Options!$D$7=&#8221;Y&#8221;,RIGHT(Main!D77,LEN(Main!D77)-FIND(Options!$F$11,(SUBSTITUTE(Main!D77,Options!$F$11,&#8221;X&#8221;,1)),1)),0)),0))</p>
<p>I wrote it as part of an angling match result calculator. The actual spreadsheet contains this formula in 50 rows x 50 columns.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vin Underwood</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/23/ugly-formulas/#comment-22152</link>
		<dc:creator>Vin Underwood</dc:creator>
		<pubDate>Sun, 21 Jan 2007 19:13:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=650#comment-22152</guid>
		<description>&lt;p&gt;I just stumbled onto this discussion thread and I feel compelled to contribute an example of a complex formula.  It certainly qualifies as &quot;long, virtually uneditable, and used in real life&quot;.   In addition it has a subtle bug, due entirely to it&#039;s unnecessary complexity.&lt;/p&gt;
&lt;p&gt;Here&#039;s the formula:&lt;/p&gt;
&lt;p&gt;=IF(D8Assumptions!$C$39),(Assumptions!$C$39*Assumptions!$D$39)+((&#039;volumes including CFS&#039;!D8-Assumptions!$C$39)*Assumptions!$D$40),IF(AND(&#039;volumes including CFS&#039;!D8Assumptions!$C$40),(Assumptions!$C$39*Assumptions!$D$39)+((Assumptions!$C$40-Assumptions!$C$39)*Assumptions!$D$40)+((&#039;volumes including CFS&#039;!D8-Assumptions!$C$40)*Assumptions!$D$41),(Assumptions!$C$39*Assumptions!$D$39)+((Assumptions!$C$40-Assumptions!$C$39)*Assumptions!$D$40)+((Assumptions!$C$41-Assumptions!$C$40)*Assumptions!$D$41)+((&#039;volumes including CFS&#039;!D8-Assumptions!$C$41)*Assumptions!$D$42))))&lt;/p&gt;
&lt;p&gt;It&#039;s &quot;only&quot; 741 characters.&lt;/p&gt;
&lt;p&gt;The formula implements a very standard &quot;tiered pricing&quot; formula, where the marginal price at each tier is lower as the total volume increases.&lt;/p&gt;
&lt;p&gt;I found the bug by trying to simplify the formula.  Here&#039;s my first marginal improvement:&lt;/p&gt;
&lt;p&gt;=IF(D8Tier1Threshold),(Tier1Threshold*Tier1Price)+((D8-Tier1Threshold)*Tier2Price),IF(AND(D8Tier2Threshold),(Tier1Threshold*Tier1Price)+((Tier2Threshold-Tier1Threshold)*Tier2Price)+((D8-Tier2Threshold)*Tier3Price),(Tier1Threshold*Tier1Price)+((Tier2Threshold-Tier1Threshold)*Tier2Price)+((Tier3Threshold-Tier2Threshold)*Tier3Price)+((D8-Tier3Threshold)*Tier4Price))))&lt;/p&gt;
&lt;p&gt;This helps a little bit I guess.&lt;/p&gt;
&lt;p&gt;To make a significant improvement I substituted a VLOOKUP as follows:&lt;/p&gt;
&lt;p&gt;=VLOOKUP(D8,Residency_Pricing_Table,4,TRUE)+(D8-VLOOKUP(D8,Residency_Pricing_Table,2,TRUE))*VLOOKUP(D8,Residency_Pricing_Table,3,TRUE)&lt;/p&gt;
&lt;p&gt;It must be paired with the following table, with a range name &quot;Residency_Pricing_Table&quot;:&lt;/p&gt;
&lt;p&gt;Account    Tier Lower&lt;br&gt;
Range        Boundary     Rate     Cum Cost&lt;br&gt;
0                   0   0.0300            0&lt;br&gt;
4,500,000   4,500,000   0.0250   135,000.00&lt;br&gt;
6,000,000   6,000,000   0.0200   172,500.00&lt;br&gt;
9,000,000   9,000,000   0.0150   232,500.00&lt;/p&gt;
&lt;p&gt;I think this is a vast improvement.  However, I went one step further.  The final version of the formula looks like this:&lt;/p&gt;
&lt;p&gt;=TieredPrice(D8,Residency_Pricing_Table)&lt;/p&gt;
&lt;p&gt;The User Function is:&lt;/p&gt;
&lt;p&gt;Function TieredPrice(number, rngInput As Range)&lt;br&gt;
    Application.Volatile&lt;br&gt;
&#039;&lt;br&gt;
&#039;   A Tiered Pricing Table always has four columns:&lt;br&gt;
&#039;       1:  the vlookup column, tier lower boundary&lt;br&gt;
&#039;       2:  = col 1, data as the tier lower boundary&lt;br&gt;
&#039;       3:  the tier marginal price&lt;br&gt;
&#039;       4:  the cumulative cost up to the lower boundary of the tier&lt;br&gt;
&#039;&lt;br&gt;
&#039;   The table can have any number of rows (tiers)&lt;br&gt;
&#039;&lt;br&gt;
    CumCost = Application.WorksheetFunction.VLookup(number, rngInput, 4, True)&lt;br&gt;
    NumInTier = number - Application.WorksheetFunction.VLookup(number, rngInput, 2, True)&lt;br&gt;
    CostInTier = NumInTier * Application.WorksheetFunction.VLookup(number, rngInput, 3, True)&lt;/p&gt;
&lt;p&gt;    TieredPrice = CumCost + CostInTier&lt;br&gt;
End Function&lt;/p&gt;
&lt;p&gt;The erroneous spreadsheet had tiered pricing formulas for many different components.  The beauty of this function is that it works for any tiered formula, regardless of the number of tiers.  Just pass the named range for the formula table to the function.&lt;/p&gt;
&lt;p&gt;Soapbox comment:  I believe there is never justification for a long, complex formula.  Every effort should be made to simplify - often with User Functions.  (I suppose the &quot;final&quot; version of a spreadsheet that must be optimized for speed would be a valid exception.  But what spreadsheet is ever final?)&lt;/p&gt;
&lt;p&gt;Regards,&lt;br&gt;
Vin Underwood&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I just stumbled onto this discussion thread and I feel compelled to contribute an example of a complex formula.  It certainly qualifies as &#8220;long, virtually uneditable, and used in real life&#8221;.   In addition it has a subtle bug, due entirely to it&#8217;s unnecessary complexity.</p>
<p>Here&#8217;s the formula:</p>
<p>=IF(D8Assumptions!$C$39),(Assumptions!$C$39*Assumptions!$D$39)+((&#8216;volumes including CFS&#8217;!D8-Assumptions!$C$39)*Assumptions!$D$40),IF(AND(&#8216;volumes including CFS&#8217;!D8Assumptions!$C$40),(Assumptions!$C$39*Assumptions!$D$39)+((Assumptions!$C$40-Assumptions!$C$39)*Assumptions!$D$40)+((&#8216;volumes including CFS&#8217;!D8-Assumptions!$C$40)*Assumptions!$D$41),(Assumptions!$C$39*Assumptions!$D$39)+((Assumptions!$C$40-Assumptions!$C$39)*Assumptions!$D$40)+((Assumptions!$C$41-Assumptions!$C$40)*Assumptions!$D$41)+((&#8216;volumes including CFS&#8217;!D8-Assumptions!$C$41)*Assumptions!$D$42))))</p>
<p>It&#8217;s &#8220;only&#8221; 741 characters.</p>
<p>The formula implements a very standard &#8220;tiered pricing&#8221; formula, where the marginal price at each tier is lower as the total volume increases.</p>
<p>I found the bug by trying to simplify the formula.  Here&#8217;s my first marginal improvement:</p>
<p>=IF(D8Tier1Threshold),(Tier1Threshold*Tier1Price)+((D8-Tier1Threshold)*Tier2Price),IF(AND(D8Tier2Threshold),(Tier1Threshold*Tier1Price)+((Tier2Threshold-Tier1Threshold)*Tier2Price)+((D8-Tier2Threshold)*Tier3Price),(Tier1Threshold*Tier1Price)+((Tier2Threshold-Tier1Threshold)*Tier2Price)+((Tier3Threshold-Tier2Threshold)*Tier3Price)+((D8-Tier3Threshold)*Tier4Price))))</p>
<p>This helps a little bit I guess.</p>
<p>To make a significant improvement I substituted a VLOOKUP as follows:</p>
<p>=VLOOKUP(D8,Residency_Pricing_Table,4,TRUE)+(D8-VLOOKUP(D8,Residency_Pricing_Table,2,TRUE))*VLOOKUP(D8,Residency_Pricing_Table,3,TRUE)</p>
<p>It must be paired with the following table, with a range name &#8220;Residency_Pricing_Table&#8221;:</p>
<p>Account    Tier Lower<br />
Range        Boundary     Rate     Cum Cost<br />
0                   0   0.0300            0<br />
4,500,000   4,500,000   0.0250   135,000.00<br />
6,000,000   6,000,000   0.0200   172,500.00<br />
9,000,000   9,000,000   0.0150   232,500.00</p>
<p>I think this is a vast improvement.  However, I went one step further.  The final version of the formula looks like this:</p>
<p>=TieredPrice(D8,Residency_Pricing_Table)</p>
<p>The User Function is:</p>
<p>Function TieredPrice(number, rngInput As Range)<br />
    Application.Volatile<br />
&#8216;<br />
&#8216;   A Tiered Pricing Table always has four columns:<br />
&#8216;       1:  the vlookup column, tier lower boundary<br />
&#8216;       2:  = col 1, data as the tier lower boundary<br />
&#8216;       3:  the tier marginal price<br />
&#8216;       4:  the cumulative cost up to the lower boundary of the tier<br />
&#8216;<br />
&#8216;   The table can have any number of rows (tiers)<br />
&#8216;<br />
    CumCost = Application.WorksheetFunction.VLookup(number, rngInput, 4, True)<br />
    NumInTier = number &#8211; Application.WorksheetFunction.VLookup(number, rngInput, 2, True)<br />
    CostInTier = NumInTier * Application.WorksheetFunction.VLookup(number, rngInput, 3, True)</p>
<p>    TieredPrice = CumCost + CostInTier<br />
End Function</p>
<p>The erroneous spreadsheet had tiered pricing formulas for many different components.  The beauty of this function is that it works for any tiered formula, regardless of the number of tiers.  Just pass the named range for the formula table to the function.</p>
<p>Soapbox comment:  I believe there is never justification for a long, complex formula.  Every effort should be made to simplify &#8211; often with User Functions.  (I suppose the &#8220;final&#8221; version of a spreadsheet that must be optimized for speed would be a valid exception.  But what spreadsheet is ever final?)</p>
<p>Regards,<br />
Vin Underwood</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kurt</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/23/ugly-formulas/#comment-21607</link>
		<dc:creator>kurt</dc:creator>
		<pubDate>Thu, 23 Nov 2006 19:46:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=650#comment-21607</guid>
		<description>&lt;p&gt;can anyone figure out a formula for me;&lt;/p&gt;
&lt;p&gt;i want to find the total number of bills i paid for a certain month&lt;/p&gt;
&lt;p&gt;example:&lt;/p&gt;
&lt;p&gt;I paid a bill on 10-Oct-06, 13-Oct-06, 17-Oct-06 &amp; 27-Oct-06.  There has to be some formula out there in which i can somehow enter  &gt;= 01-Oct-06 &amp;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>can anyone figure out a formula for me;</p>
<p>i want to find the total number of bills i paid for a certain month</p>
<p>example:</p>
<p>I paid a bill on 10-Oct-06, 13-Oct-06, 17-Oct-06 &amp; 27-Oct-06.  There has to be some formula out there in which i can somehow enter  &gt;= 01-Oct-06 &amp;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

