<?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/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>User Defined Function Archives - Excel Zoom</title>
	<atom:link href="https://excelzoom.com/tag/user-defined-function/feed/" rel="self" type="application/rss+xml" />
	<link>https://excelzoom.com/tag/user-defined-function/</link>
	<description>...because it&#039;s more than just a calculator</description>
	<lastBuildDate>Mon, 06 Apr 2020 17:36:19 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>

<image>
	<url>https://excelzoom.com/wp-content/uploads/2022/04/favicon.ico</url>
	<title>User Defined Function Archives - Excel Zoom</title>
	<link>https://excelzoom.com/tag/user-defined-function/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Introduction to VBA for MS Excel</title>
		<link>https://excelzoom.com/introduction-to-vba-for-ms-excel/</link>
					<comments>https://excelzoom.com/introduction-to-vba-for-ms-excel/#respond</comments>
		
		<dc:creator><![CDATA[Mark]]></dc:creator>
		<pubDate>Mon, 12 Feb 2018 20:07:40 +0000</pubDate>
				<category><![CDATA[Macros]]></category>
		<category><![CDATA[Event Procedure]]></category>
		<category><![CDATA[User Defined Function]]></category>
		<category><![CDATA[VBA]]></category>
		<guid isPermaLink="false">http://excelzoom.com/?p=3582</guid>

					<description><![CDATA[<p>Introduction: We use programming language to build applications that we use in our work and domestic lives. This is true for almost every computer application that we use. There are numerous languages out there, that are at the disposal of the programmers that use them for various purposes. The language that is used to add more [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://excelzoom.com/introduction-to-vba-for-ms-excel/">Introduction to VBA for MS Excel</a> appeared first on <a rel="nofollow" href="https://excelzoom.com">Excel Zoom</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2><strong>Introduction:</strong></h2>
<p>We use programming language to build applications that we use in our work and domestic lives. This is true for almost every computer application that we use. There are numerous languages out there, that are at the disposal of the programmers that use them for various purposes. The language that is used to add more functionality to MS Office, or is used as a default programming language for MS Office is called Visual Basic for Application or simply VBA.</p>
<p>Excel being part of the MS Office suite uses the same programming language and we often found functions and macros written in this language in our excel worksheets. Such written functions are called User Defined Functions, similarly code written to automate the task in Excel are called Macros.</p>
<p>In today&#8217;s tutorial we will explore what is VBA, its different features, a brief introduction to VBA programming and more.</p>
<h2><strong>Accessing the VBA Window in MS Excel:</strong></h2>
<p>As we move on to use Excel VBA, the first thing is see where we have this programming option in Excel. The easiest way of accessing the code editor window in excel is to press Alt+F11 while you are using an Excel worksheet. Alternatively see <a href="https://excelzoom.com/how-to-open-excel-vba-editor/">How to Open Excel VBA Editor </a></p>
<p><img fetchpriority="high" decoding="async" class="aligncenter size-full wp-image-3587" src="https://excelzoom.com/wp-content/uploads/2018/02/01.jpg" alt="" width="1366" height="725" srcset="https://excelzoom.com/wp-content/uploads/2018/02/01.jpg 1366w, https://excelzoom.com/wp-content/uploads/2018/02/01-600x318.jpg 600w" sizes="(max-width: 1366px) 100vw, 1366px" /></p>
<p>This is the window where we will put all the macros and the functions.</p>
<h2><strong>Classification of codes used in MS Excel VBA:</strong></h2>
<p>The code we write in VBA can be classified in either of the following three categories:</p>
<h3><strong>User Defined Function:</strong></h3>
<p>Excel has numerous functions that can be used as we need them. Out of these functions, we came across the situation where neither of them fits in or the formula based solution is too complicated to use, we revert to this option.</p>
<p>We revert to writing function that fulfill a situational or a a very specific need. For example consider following set of code that is written to find the if value is less then zero, is zero or more then it:</p>
<pre style="padding-left: 30px;"><span style="color: #0000ff;">Function FindSign(number)
Select Case number
Case Is &lt; 0
FindSign = “-ive”
Case 0
FindSign = “Zero”
Case Is &gt; 0
FindSign = “+ive”
End Select
End Function</span></pre>
<p>Note that the function always start with “Func” that is used to show its a function. In the above example of function, we have used a special command called “Case” to find if a number is less then zero (or negative), equal to zero or is positive (greater then zero). This is just a start-up example of function that can be easily written with IF() statements, but, we can produce really complicated functions as well.</p>
<p><img decoding="async" class="aligncenter size-full wp-image-3592" src="https://excelzoom.com/wp-content/uploads/2018/02/06.jpg" alt="" width="540" height="335" /></p>
<p>In order for these functions to work, we need to place them in “Modules”. A module can be placed or inserted in a worksheet when we have VBA windows enabled. One need to go to Insert &gt; Module and click to insert the module. Once inserted we will select it and place the function code there.</p>
<p>Once we have done this, we will be able to access the function from functions window.</p>
<p><img decoding="async" class="aligncenter size-full wp-image-3589" src="https://excelzoom.com/wp-content/uploads/2018/02/03.jpg" alt="" width="447" height="383" /></p>
<p>Thus a user can write any thing he wants to be used a User Defined Function.</p>
<h3><strong>The Macros:</strong></h3>
<p>Macros also belong to the VBA family and are used to automate the task that are frequently done by a user. Thus they are used to speed up the work and reduce burden on end users. An example of already incorporated macros in MS Office is the option to save file after certain time period. Thus certainly reduced the burden on user and also reduces the chances of loosing data if file is not saved.</p>
<p>Besides this, there are numerous situations where VBA is a must required. Consider following example of vba that will highlight all cells that contains formulas in the range:</p>
<pre style="padding-left: 30px;"><span style="color: #0000ff;">Sub CellWithFormulas()
Dim Dataset As Range
Set Dataset = Selection
Dataset.SpecialCells(xlCellTypeFormulas).Interior.Color = vbRed
End Sub</span></pre>
<p>The macros is placed in the same module where we have placed the function. When we execute this macro from the developer&#8217;s tab, we have following result:</p>
<p>In this example, cell B3 and B7 contains the formulas.</p>
<h3><strong>Event Procedures:</strong></h3>
<p>As is indicated by the name, these are the codes that are meant to be used when something or some event happens. The example of an event could be the opening of a workbook, inserting a number in a cell, clicking some cell and many more.</p>
<p>Events Procedures are useful as they are active behind the scene are run as something happens. A very useful example of even procedure is one that is used to highlight the row and column as active cell changes. This makes reading and tracking the data very easy.</p>
<pre style="padding-left: 30px;"><span style="color: #0000ff;">Private Sub ActiveCellHighlight(ByVal Target As Range)
Application.ScreenUpdating = False
Cells.Interior.ColorIndex = 0 
Target.Interior.ColorIndex = 6
Application.ScreenUpdating = True
End Sub</span></pre>
<p>The result is a highlighted active cell.</p>
<p><img decoding="async" class="aligncenter size-full wp-image-3590" src="https://excelzoom.com/wp-content/uploads/2018/02/04.jpg" alt="" width="236" height="239" srcset="https://excelzoom.com/wp-content/uploads/2018/02/04.jpg 236w, https://excelzoom.com/wp-content/uploads/2018/02/04-100x100.jpg 100w" sizes="(max-width: 236px) 100vw, 236px" /></p>
<h2><strong>Debugging your code?</strong></h2>
<p>The code that a user writes is not always correct and contains errors. In this case we need a debugging mechanism to find the mistake that we have done. For such situation, VBA editors provides us with a handy tool called “Immediate Window”.</p>
<p>This window can be accessed by using key Ctrl + G when VBA editor is active. This window can be used to execute a line of code, to get the information related to the worksheets, set values to the variables and run macros.</p>
<p>For example in the following screen shot, the initial value of the active cell with yellow fill was 10, as we have found by command ?activecell.value. The value is then re-assigned by using the assignment operator and the offset command.</p>
<p>The offset command lets the value to be on the left side of the cells at difference of 2 columns (hence the negative sign: -2). and when we reprint the value of active cell, it is 5.</p>
<p><img decoding="async" class="aligncenter size-full wp-image-3591" src="https://excelzoom.com/wp-content/uploads/2018/02/05.jpg" alt="" width="621" height="384" srcset="https://excelzoom.com/wp-content/uploads/2018/02/05.jpg 621w, https://excelzoom.com/wp-content/uploads/2018/02/05-600x371.jpg 600w" sizes="(max-width: 621px) 100vw, 621px" /></p>
<p>In the same way, this can be used to run macros, testing small snipts of vba and much more.</p>
<h2><strong>Conclusion:</strong></h2>
<p>VBA is a very handy tool for excel users and gives them a lot of control over their worksheets. The use of VBA makes worksheets look more professional and more interactive. Please download the <a href="https://www.dropbox.com/s/ygu2neu6a5klf5v/Sample.xlsm?dl=1">attached file</a> for example and the vba code.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://excelzoom.com/introduction-to-vba-for-ms-excel/">Introduction to VBA for MS Excel</a> appeared first on <a rel="nofollow" href="https://excelzoom.com">Excel Zoom</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://excelzoom.com/introduction-to-vba-for-ms-excel/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>7 Excel Formatting Tricks</title>
		<link>https://excelzoom.com/7-excel-formatting-tricks/</link>
					<comments>https://excelzoom.com/7-excel-formatting-tricks/#comments</comments>
		
		<dc:creator><![CDATA[Mark]]></dc:creator>
		<pubDate>Wed, 18 Jun 2014 20:52:14 +0000</pubDate>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Cell]]></category>
		<category><![CDATA[Formats]]></category>
		<category><![CDATA[Paste]]></category>
		<category><![CDATA[Shortcuts]]></category>
		<category><![CDATA[User Defined Function]]></category>
		<guid isPermaLink="false">http://excelzoom.com/?p=539</guid>

					<description><![CDATA[<p>Microsoft Excel, like any other Office product offers it&#8217;s users simple and intuitive ways to format your data. Many of these formatting options are great for using once or twice, but what if you find yourself needing the same format dozens of times, or need a format that doesn&#8217;t exist? The following Excel formatting tricks [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://excelzoom.com/7-excel-formatting-tricks/">7 Excel Formatting Tricks</a> appeared first on <a rel="nofollow" href="https://excelzoom.com">Excel Zoom</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Microsoft Excel, like any other Office product offers it&#8217;s users simple and intuitive ways to format your data. Many of these formatting options are great for using once or twice, but what if you find yourself needing the same format dozens of times, or need a format that doesn&#8217;t exist? The following Excel formatting tricks will help you work more efficiently.<br />
</p>
<p>The post <a rel="nofollow" href="https://excelzoom.com/7-excel-formatting-tricks/">7 Excel Formatting Tricks</a> appeared first on <a rel="nofollow" href="https://excelzoom.com">Excel Zoom</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://excelzoom.com/7-excel-formatting-tricks/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Create a User Defined Function</title>
		<link>https://excelzoom.com/create-a-user-defined-function/</link>
					<comments>https://excelzoom.com/create-a-user-defined-function/#comments</comments>
		
		<dc:creator><![CDATA[Mark]]></dc:creator>
		<pubDate>Tue, 02 Jun 2009 11:35:25 +0000</pubDate>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[UDF]]></category>
		<category><![CDATA[User Defined Function]]></category>
		<category><![CDATA[VBA]]></category>
		<guid isPermaLink="false">http://excelzoom.com/?p=152</guid>

					<description><![CDATA[<p>Excel allows you to create your own &#8220;User Defined Functions&#8221; (UDF) that can be used the same way as any other built-in function in Excel (i.e. IF, SUM, VLOOKUP, etc.).  With a little knowledge of VBA code, you can create your own function to do pretty much whatever you want. To illustrate how to create [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://excelzoom.com/create-a-user-defined-function/">Create a User Defined Function</a> appeared first on <a rel="nofollow" href="https://excelzoom.com">Excel Zoom</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Excel allows you to create your own &#8220;User Defined Functions&#8221; (UDF) that can be used the same way as any other built-in function in Excel (i.e. IF, SUM, VLOOKUP, etc.).  With a little knowledge of VBA code, you can create your own function to do pretty much whatever you want.</p>
<p>To illustrate how to create a UDF, we&#8217;ll create a function that calculates fuel consumption in miles per gallon.</p>
<ul>
<li>First, open a new Excel workbook.</li>
<li>Open VBA (Alt+F11)</li>
<li>Right click the workbook&#8217;s name (i.e. VBAProject (Book1))and select Insert | Module</li>
</ul>
<p><br />
In order to calculate your vehicle&#8217;s fuel consumption in miles per gallon, you&#8217;ll need to know a couple things:</p>
<ul>
<li>How many miles driven (ending miles less beginning miles)</li>
<li>Number of gallons used </li>
<li>Miles per Gallon = (Ending Miles &#8211; Beginning Miles) / Gallons Used</li>
</ul>
<p>Now, from the new module you opened in VBA, begin typing your function as follows.</p>
<p style="padding-left: 30px;"></p>
<p>After entering the UDF in your module, return back to the Excel workbook and test it out. </p>
<p>Take a look at the example below to see how this function works the same way any built in function would work.</p>
<p> </p>
<p><img decoding="async" src="https://excelzoom.com/images/mpg.jpg" alt="User Defined Function" /></p>
<p>You can create your own functions to do just about any calculation you can think of, as well as manipulating text.</p>
<p> These functions can be saved in the workbook you&#8217;re working in, or can be saved as an add-in if you wish to use it in more than one workbook.</p>
<p>To save the workbook as an add-in, simply click File | Save As enter a name for the file, then change the file type to Microsoft Excel Add-In (*.xla).  In Excel 2007, you can then import the add-in by clicking Excel Options after clicking the Office Button, then clicking Add-Ins.  Towards the bottom of the screen, select Manage: Excel Add-Ins and click Go.  In earlier versions of Excel, click Tools | Add-Ins.  On the next screen, click Browse and find the location of your Add-In.  Make sure it is checked in the list, and hit OK.  You should now be able to access your Add-In in any file you&#8217;re using.</p>
<p>The post <a rel="nofollow" href="https://excelzoom.com/create-a-user-defined-function/">Create a User Defined Function</a> appeared first on <a rel="nofollow" href="https://excelzoom.com">Excel Zoom</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://excelzoom.com/create-a-user-defined-function/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
