<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>error-handling on S Anand</title>
    <link>https://www.s-anand.net/blog/tag/error-handling/</link>
    <description>Recent content in error-handling on S Anand</description>
    <generator>Hugo -- 0.164.0</generator>
    <language>en-us</language>
    <lastBuildDate>Mon, 23 Mar 2009 15:39:30 +0000</lastBuildDate>
    <atom:link href="https://www.s-anand.net/blog/tag/error-handling/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Creating user friendly 404 pages</title>
      <link>https://www.s-anand.net/blog/creating-user-friendly-404-pages/</link>
      <pubDate>Sun, 18 Mar 2007 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/creating-user-friendly-404-pages/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;http://www.codinghorror.com/blog/archives/000819.html&#34;&gt;Creating user friendly 404 pages&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>User-defined functions in Excel</title>
      <link>https://www.s-anand.net/blog/user-defined-functions-in-excel/</link>
      <pubDate>Fri, 01 Sep 2006 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/user-defined-functions-in-excel/</guid>
      <description>&lt;p&gt;Excel lets you create your own functions. If you wanted to create a function that returned the distance between two points (x1,y1) and (x2,y2), you can create a function DIST that takes these 4 parameters, and use it as shown below.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://www.s-anand.net/blog/assets/flickr-example-of-a-user-defined-function-in-excel_231273003_o-gif.webp&#34;&gt;&lt;img alt=&#34;Example of a user-defined function in Excel&#34; loading=&#34;lazy&#34; src=&#34;https://www.s-anand.net/blog/assets/flickr-example-of-a-user-defined-function-in-excel_231273003_o-gif.webp&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To create such a function,&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;press Alt-F11 to open the Visual Basic Editor&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;insert a new module (Alt-I-M)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;type the following code:&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://www.s-anand.net/blog/assets/flickr-visual-basic-code-for-the-dist-user-defined-excel-function_231278952_o-gif.webp&#34;&gt;&lt;img alt=&#34;Visual Basic code for the DIST user-defined Excel function&#34; loading=&#34;lazy&#34; src=&#34;https://www.s-anand.net/blog/assets/flickr-visual-basic-code-for-the-dist-user-defined-excel-function_231278952_o-gif.webp&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Anything you declare as a &amp;ldquo;Function&amp;rdquo; in Excel&amp;rsquo;s Visual Basic automatically becomes visible in the Insert-Function dialog box under the category &amp;ldquo;User Defined&amp;rdquo; (see &lt;a href=&#34;http://www.dailydoseofexcel.com/archives/category/vba/user-defined-functions/&#34;&gt;examples&lt;/a&gt;). The function is normally saved with the file. This is a good idea if you&amp;rsquo;re going to distribute the file. You can also save your functions in your &lt;a href=&#34;http://www.google.com/search?q=personal.xls&amp;amp;btnI=I&#39;m+Feeling+Lucky&#34;&gt;personal.xls&lt;/a&gt; file and load it on startup.&lt;/p&gt;
&lt;p&gt;There are 3 places where I suggest using UDFs.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;You need to repeat a formula or use an additional cell to get the job done (e.g. replace Excel errors with empty strings)&lt;/li&gt;
&lt;li&gt;You &lt;a href=&#34;https://www.s-anand.net/blog/user-defined-functions-to-get-cell-formatting/&#34;&gt;can&amp;rsquo;t get the information&lt;/a&gt; from a formula (e.g. a cell&amp;rsquo;s background colour)&lt;/li&gt;
&lt;li&gt;It&amp;rsquo;s very cumbersome to get the information using formulas (e.g. regular expressions)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Let&amp;rsquo;s take the first one: &lt;strong&gt;replace Excel errors with empty strings&lt;/strong&gt;. Normally, you&amp;rsquo;d store the results in a cell (say A2), and have another cell with the formula =IF(ISERROR(A2),&amp;quot;&amp;quot;,A2). Instead, create this function NOERROR:&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://www.s-anand.net/blog/assets/flickr-function-noerror-in-excel-visual-basic_231297813_o-gif.webp&#34;&gt;&lt;img alt=&#34;Function NOERROR in Excel Visual Basic&#34; loading=&#34;lazy&#34; src=&#34;https://www.s-anand.net/blog/assets/flickr-function-noerror-in-excel-visual-basic_231297813_o-gif.webp&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now you can enclose any Excel function inside a NOERROR() and it&amp;rsquo;ll filter out the errors.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://www.s-anand.net/blog/assets/flickr-how-the-noerror-function-is-used_231297815_o-gif.webp&#34;&gt;&lt;img alt=&#34;How the NOERROR function is used&#34; loading=&#34;lazy&#34; src=&#34;https://www.s-anand.net/blog/assets/flickr-how-the-noerror-function-is-used_231297815_o-gif.webp&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Notice that cell E2 would&amp;rsquo;ve had a #N/A error if you&amp;rsquo;d just used the VLOOKUP. This function also filters out #REF, #DIV/0!, #NAME? and all other errors.&lt;/p&gt;
&lt;p&gt;BTW, you see column F displaying the formula in column E. I didn&amp;rsquo;t type it out. That&amp;rsquo;s another UDF.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://www.s-anand.net/blog/assets/flickr-formulastring-function-returns-the-formula-of-a-cell_231297817_o-gif.webp&#34;&gt;&lt;img alt=&#34;FormulaString function returns the formula of a cell&#34; loading=&#34;lazy&#34; src=&#34;https://www.s-anand.net/blog/assets/flickr-formulastring-function-returns-the-formula-of-a-cell_231297817_o-gif.webp&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I will talk about the other two places where you use UDFs tomorrow.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;comments&#34;&gt;Comments&lt;/h2&gt;
&lt;!-- wp-comments-start --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Greg&lt;/strong&gt; &lt;em&gt;4 Apr 2007 3:15 pm&lt;/em&gt;:
This is very helpful! I am having a problem however; I defined the functions in personal.xls (loaded upon startup) and they always work there, but they aren&amp;rsquo;t available when working with a different file (I get the #NAME error). I also then created variants of them in the specific file, but although they worked, once I made some changes in the file (added a column), they no longer worked even though I re-did the reference properly. Any ideas?&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- wp-comments-end --&gt;
</description>
    </item>
    <item>
      <title>Apologetic software</title>
      <link>https://www.s-anand.net/blog/apologetic-software/</link>
      <pubDate>Thu, 22 Jul 2004 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/apologetic-software/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;http://www.newscientist.com/news/news.jsp?id=ns99996156&#34;&gt;Apologetic software&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
  </channel>
</rss>
