web 2.0


What is the factorial of 0.5 (0.5!)?

If you use Excel and enter the following formula: =FACT(0.5) the answer will be one. However, if you open a more rustic tool such as the Windows Calculator and try again, you will get 0.886226925510…

So, how can a tool such as the Windows calculator come up with the correct answer when Excel can only return 1? What about the factorial of 0.75 (0.75!)? Again, Excel returns 1 whereas the Windows calculator gets the correct answer: 0.919062526898...

Both numbers are close to one, but they are not exactly one.

The trouble is that Excel is using the general rule that states that the factorial is, in fact, the product of all integers in the series. So 4! Is given by =(4*3*2*1)=24. Unfortunately, the story does not end there for factorials.

When dealing with factorials the above works fine for integers. When dealing with non-integers (greater than zero), then we need the natural logarithm of the gamma function to get it to work. This function uses the concept of limits to determine the factorial of a number, so the factorial of 5 (5!) would be 119.99999998… when using gamma instead of the integer 120 (you can obviously round to 120, since it is effectively this number). For a discussion on the gamma function check this link: http://numbers.computation.free.fr/Constants/Miscellaneous/gammaFunction.html

Supposing the number you wish to find its factorial is located in cell A1, your formula using the gamma function would be:

=A1*EXP(GAMMALN(A1))

The last thing to rember is that this is for positive numbers only…

Tags: , , ,

Microsoft Excel

How to: Excel 2007 Conditional Formatting using formulas

Let us suppose that you have a list. In this list, you want to identify the cells that contain a certain text. Figure 1 shows the initial setup of our problem:



Figure 1 -
Conditionally formatting based on text in a cell

What we plan to do is to identify the products that contain the word “used” (for now). We show you two different ways to get this done.

In the first example, we type in the word directly into the formula. In the second example, we do this by using a validation list from where you can choose what to look for and then the CF is applied.

To begin with, choose the area containing the data (starting from the top-most cell). Add a new rule and choose the option Use a formula to determine which cells to format. In the formula box, you must enter the following formula: =IF(NOT(ISERROR(FIND("used",A1,1))),1,0)=1. Choose the formatting of your liking. Figure 2
shows the step visually:


Figure 2 -
Entering the conditional formatting formula

Obviously that, as it is, the conditional formatting is pretty much useless to us. What if we want to format whenever the word “new” comes up? Or when “repaired” comes up? In theses case it does not take a genious to figure out that we’re in serious trouble. It is simply not practical keep changing the value around everytime we need to conditionally format based on a word found in the text.

The solution is to implement a truly functional formula. In this case, we can use a data validation list to choose from (we discuss data validation in details in the second part of this eBooklet).

Here are the steps:

·        
Type in the word “repaired, used and new” in the range F1:F3;
·        
Select cell D1 where the data validation will be inserted;
·         Open the data validation tool (Data tab à Data tools group à Data Validation splitbutton à
Data validation button);
·        
From the Allow dropdown list, choose List;
·        
In the Source field, choose the range F1:F3;
·        
Click OK to finish.

Now, when you click on D1, you will get the validated list as shown in Figure 3
:


Figure 3 -
Validation list to be used in our conditional formatting

Now, all you need to do is to change the original formula to point to cell D1 as shown in
Figure 4:


Figure 4 -
Edited formula

If you are wondering above the “=1” at the end, we only added this to make it explicit that the formula is evaluating to 1 (true) so that the conditional formatting can be applied. There is not need to have the “=1” at the end of the formula. It is entirely up to you.

You can now select from the validated list any of the values and see your conditional formatting at work as shown in Figure 5
:


Figure 5 - Final step o four conditional formatting with data validation


You may also want to read this article (
http://www.excelguru.ca/blog/2009/04/23/making-an-icon-set-show-only-two-conditions/) from my fellow MVP, Ken Puls.

Tags: , , , , , ,

Microsoft Excel

User-Defined Function (UDF) naming problem

 


When you create a User-Defined function (UDF) you need to ensure that the function name is unique. If it conflicts with an internal name, then you will get an error.

In this video, I show this scenario where a function named ALERT() is created and it conflicts with an Excel 4.0 macro function name. You will also learn how you can figure out these names as to avoid future problems.




 

Tags: , , ,

Microsoft Excel | Microsoft Excel - VBA

Using "Redemption" to send a safe Outlook message

This short tip shows how to use Redemption’s SafeOutlook Library to send e-mail messages without that annoyance of the security warning for Outlook. You can also use Redemption to create other safe Outlook objects...

To use this code you will need to download the Redemption dll and install on your PC. You can download it from http://www.dimastr.com/redemption/redemption.zip. After installation, you should do the following:

1.       On the VBE, go to Tool à References and from the list install the references for SafeOutlook Library

2.       On the VBE, go to Tool à References and from the list install the references for Microsoft Outlook X.x Object Library (where “X.x” indicates the version of your Outlook)

With all that sorted out, we are ready for the code:
 

 

Sub sendMailThroughRedempetion()

    Dim appOL               As Outlook.Application
    Dim myEmail             As Outlook.MailItem
    Dim mySafeEmail         As Redemption.SafeMailItem

    Set appOL = CreateObject("Outlook.Application")
    Set myEmail = appOL.CreateItem(olMailItem)
    Set mySafeEmail = CreateObject("Redemption.SafeMailItem")

    With mySafeEmail
        .Item = myEmail
        .Recipients.Add "someone@somewhere.com"
        .Recipients.ResolveAll
        .Subject = "My test redemption message"
        .Body = "Body of my message"
        .Send
    End With
End Sub

Tags: , ,

Microsoft Outlook | Microsoft Outlook - VBA