Professional Documents
Culture Documents
All Tips
List all tips, by category
Round Values To The Nearest Fraction
Browse all tips C ategory: Formulas | [Item URL]
=IF(ISERROR(A1/B1),"",A1/B1)
You can adapt this technique to any operation. The original formula serves as the argument for
the ISERROR() function, and it repeats as the last argument of the IF() function. Like this:
=IF(ISERROR(OriginalFormula),"",OriginalFormula)
Excel provides tw o w ays to accomplish this. The "traditional" technique goes something like
this:
converted by Web2PDFConvert.com
1. Enter 1.05 into any blank cell.
2. Select the cell and choose Edit, Copy.
3. Select the range of values and choose Edit, Paste Special.
4. Choose the Multiply option and click OK.
5. Delete the cell that contains the 1.05.
Q. I've created some clever formulas, and I don't want anyone else to see them. Is it
possible to hide the formulas but display the results?
Every cell has tw o key properties: locked and hidden. A locked cell can't be changed, and the
contents of a hidden cell don't appear in the formula bar w hen the cell is selected. By default,
every cell is locked and not hidden. But it's important to remember that these attributes have
no effect unless the w orksheet itself is protected.
First, to change the attributes, select the appropriate cell or range and then choose Format,
Cells. In the Format Cells dialog box, click the Protection tab and select Locked or Hidden (or
both). Unlock cells that accept user input, and lock formula and other cells that should stay
unchanged (such as titles). To prevent others from seeing your formulas, lock and hide the
formula cells: The results of the formulas w ill be visible, but the formulas w ill not.
Now , to protect the w orksheet, choose Tools, Protection, Protect Sheet to bring up the Protect
Sheet dialog box. Make sure the Contents box is checked. You can enter a passw ord to
prevent others from unprotecting the sheet. Locked cells in a protected sheet cannot be
edited, and other w orksheet changes are disabled. For example, no one can insert row s or
columns, change column w idth, or create embedded charts.
NOTE: Keep in mind that it is very easy to break the passw ord for a protected sheet. If you
are looking for real security, this is not the solution.
Q. Can I write a formula that returns the number of distinct entries in a range?
First, let's clarify the question. We're hunting for a formula that, given the range that contains
the values 100, 99, 98, 100, 98, 100, 98, w ould return 3. In other w ords, this range contains
three different values, some of them repeated.
This type of counting requires an array formula. The formula below , for example, counts the
number of distinct entries in the range A1:D100.
=SUM(1/COUNTIF(A1:D100, A1:D100))
W hen you enter this formula, you must press Ctrl-Shift-Enter. Pressing only Enter w ill give you
the w rong result. Excel w ill place brackets around the formula to remind you that you've
created an array formula.
The preceding formula w orks fine in many cases, but it w ill return an error if the range contains
any blank cells. The formula below (also an array formula, so input it w ith Ctrl-Shift-Enter) is
more complex, but it w ill handle a range that contains a blank cell.
Q. I find that sometimes my formulas do not get fully calculated. This often happens when
I use custom functions created with VBA.
Microsoft has acknow ledged some problems w ith the Excel calculation engine in some version
of Excel. In order to be assured that all of your formulas have been calculated, press Ctrl-Alt-F9
to force a complete recalculation.
This key combination w ill also update formulas that use custom VBA functions.
Q. I have a range of time values, but when I try to sum them, the total is never greater
than 24 hours.
W hen you add a range that contains time values, Excel ignores the hours that exceed 24. The
solution is to use a custom number format.
converted by Web2PDFConvert.com
1. Activate the cell that contains your total time
2. Choose Format, Cells.
3. In the Format Cells dialog box, click the Number tab.
4. Choose Custom from the Category list
5. Type [h]:mm into the box labeled Type.
Using brackets around the hour portion of the format string tells Excel to display hours that
exceed 24 hours.
This tip describes a technique that should be in the arsenal of every Excel user. It describes
how to use formulas to transform data.
The figure below show s a simple example. The text in column A consists of low er case letters.
The goal is to transform these cells so they display "proper" case. This w ill be done by creating
formulas that use Excel's PROPER function.
The steps below are specific to this example. But they can easily be adapted to other types of
data transformations.
converted by Web2PDFConvert.com
6. Click OK.
At this point, the w orksheet looks like this:
Creating A “Megaformula”
C ategory: Formulas | [Item URL]
This tip describes how to create w hat I call a "megaformula" -- a single formula that does the
w ork of several intermediate formulas.
An Example
The goal is to create a formula that returns the string of characters follow ing the final
occurrence of a specified character. For example, consider the text string below (w hich
happens to be a URL):
http://spreadsheetpage.com/index.php/tips
Excel does not provide a straightforw ard w ay to extract the characters follow ing the final slash
character (i.e., "tips") from this string. It is possible, how ever, do do so by using a number of
intermediate formulas. The figure below show s a multi-formula solution. The original text is in
cell A1. Formulas in A2:A6 are used to produce the desired result. The formulas are displayed
in column B.
Follow ing is a description of the intermediate formulas (w hich w ill eventually be combined into
a single formula).
1. Activate the cell that displays the final result (in this case, cell A6). Notice that it contains a
converted by Web2PDFConvert.com
reference to cell A5.
2. Activate cell A5. Press F2 and select the formula text (but omit the initial equal sign), and
press Ctrl+C to copy the text. Press Esc.
3. Re-activate cell A6 and paste the copied text to replace the reference to cell A5. The
formula in A6 is now :
=RIGHT(A1,LEN(A1)-A4)
4. The formula contains a reference to cell A4, so activate A4 and copy the formula as text.
Then replace the reference to cell A4 w ith the copied formula text. The formula now looks
like this:
RIGHT(A1,LEN(A1)-FIND(CHAR(1),A3))
5. Replace the reference to cell A3 w ith the formula text from cell A3. The formula now looks
like this:
=RIGHT(A1,LEN(A1)-FIND(CHAR(1),SUBSTITUTE(A1,"/",CHAR(1),A2)))
6. Replace the reference to cell A2 w ith the formula text from cell A2. The formula now looks
like this:
=RIGHT(A1,LEN(A1)-FIND(CHAR(1),SUBSTITUTE(A1,"/",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1,"/","")))))
The formula now refers only to cell A1, and the intermediate formula are no longer necessary.
This single formula does the w ork of five other formulas.
This general technique can be applied to other situations in w hich a final result uses several
intermediate formulas.
NOTE: You may think that using such a complex formula w ould cause the w orksheet to
calculate more slow ly. In fact, you may find just the opposite: Using a single formula in place of
multiple formulas may speed up recalculation. Any calculation speed differences, how ever, w ill
probably not be noticeable unless you have thousands of copies of the formula.
Caveat
Keep in mind that a complex formula such as this is virtually impossible to understand.
Therefore, use this type of formula only w hen you are absolutely certain that it w orks correctly
and you are sure that you w ill never need to modify it in the future. Better yet, keep a copy of
those intermediate formulas -- just in case.
Page 4 of 5 pages
[Previous page] [Next page]
converted by Web2PDFConvert.com