Saturday, January 23, 2010

Excluding Some Data from a Chart

Excel is a whiz at creating charts from your worksheet data. When the program tries to determine what should be included in a chart, it includes all the contiguous data it can find. If you want to exclude some data from the chart, then you need to be very precise in what you tell Excel.

Suppose you keep a month's worth of data in a table and create a chart based on that data. The data was collected from information generated on your company's shop floor. The data includes weekends, but you don't want the weekend data included in the chart. You could hide the rows and they would be excluded from the chart, but you still want the hidden rows to be displayed in the table. In other words, you wants them displayed in the data table, but not in the chart.

There are a couple of ways you could approach this problem. One is to simply make a copy of your data (maybe copy the whole worksheet) and then delete the rows that contain weekend data. You would still have your master data for whatever purposes you need, but you could base your chart on the modified copy of that data.

The drawback to this, of course, is that it creates two sets of data that may need to be updated or kept in sync in some way. It may be better to base your chart on a non-contiguous data range. Assume, for a moment, that your data was in A1:B15, and that there were weekends in rows 7, 8, 14, and 15. You could, within the chart, set the data range for the source data to this:

=Sheet1!$A$1:$B$6,Sheet1!$A$9:$B$13

You could also create a named range that refers to the non-contiguous ranges you want included in the chart. You could then use the named range in your chart, as a reference to the source data.

Finally, if you don't mind adding another column to your data, you could use the new column for your chart source. Assume, for a moment, that your readings are in column A and the dates of those readings are in column B. In each cell of column C you could place the following formula:

=IF(WEEKDAY(B1,2)>5,NA(),A1)

You then end up with a series of readings for all weekdays; the weekends show #N/A for the reading. You can base your chart on this data and Excel will ignore the #N/A values. You can even hide column C so it does not distract from your source data.

Posted courtesy of Tips.Net

Averaging a Non-Contiguous Range

Figuring out how to average data that is in a contiguous range of cells is easy. When the data is spread over a group of non-contiguous cells then getting the average can be a bit more challenging. Throw into the mix the need to exclude zero values from the average and the solution can be downright elusive.

Sometimes you need to average a series of non-contiguous cells, excluding any cells that may contain zero values. For example, average cells A1, C1, E1, G1, and J1, but only counting those cells that don't contain zero.

Before getting into what works, let's take a look at what doesn't work. First of all, it doesn't work to simply add the cells and divide by 5; that doesn't take zero values into account. Second, it doesn't work to use COUNTIF in the denominator of your formula, as shown here:

=(A1+C1+E1+G1+J1) / COUNTIF(A1:J1,"<>0")

This doesn't work because it examines and counts cells within the entire range of A1:J1, not just the five cells you want considered in the average. You might also think that you could select your five non-contiguous cells, give them a name, and then use the name in your formula. While Excel allows you to create the name, the following gives an error:

=SUM(MyCells) / COUNTIF(MyCells,"<>0")

It appears that COUNTIF will only work with a single contiguous range, so the non-contiguous nature of the MyCells range throws the function into a tailspin. A similar problem occurs if you try to use a non-contiguous range with the AVERAGEIF function:

=AVERAGEIF(MyCells, "<>0")

Since you can't use any of the functions you might want to use, you are left to rely on a bit longer formula to calculate the average. You can calculate the average of these five cells by applying a bit of "trickery" to your denominator, in this manner:

=(A1+C1+E1+G1+J1) / ((A1<>0)+(C1<>0)+(E1<>0)+(G1<>0)+(J1<>0))

The evaluation done on each cell in the denominator returns either a 1 (for True) or a 0 (for False) depending on whether the cell contains a non-zero value or not. This series of values is added together, providing the necessary count of non-zero cells for the denominator.

Notice that the discussion here has been all about the denominator in the formula, not the numerator. The reason is simple—you can add all five values into the numerator; zero values there don't really matter. The only place they matter is in the denominator, which is what makes calculating this average so tricky.

Posted courtesy of Tips.Net

Saturday, January 16, 2010

New Formulas in Excel 2007

Every new version of Excel seems to introduce a few new tools you can use in your formulas. Excel 2007 is no different; this tip explains what was added and where you can find further information. (This tip works with MS Excel 2007.)

Upgrading to Excel 2007 brings several new worksheet functions in the version of the program. What's needed is a good summary of what those functions are and how they can be used.

There are more than 50 new worksheet functions in Excel 2007. The majority of those were functions that had, in previous versions of the program, been in the Analysis ToolPak. A good, general intro to the new functions can be found in this blog post:
http://blogs.msdn.com/excel/archive/2005/10/20/483205.aspx

You might also, in Excel 2007, just use the Help system to find the new functions. Press the F1 key and then click the "What's New?" link. You should see a good overview of what has been added to this version of the program.

If you want to see all the added functions in one list, then the following site provides a good list. (Just scroll down to the "Functions" section of the page.)
http://visio.mvps.org/Excel_2007.htm

Posted courtesy of Tips.Net

Sunday, January 10, 2010

Sequential Page Numbers Across Worksheets

How do you want your page numbers to appear on your printed worksheets? Chances are good that you want them to be sequential, regardless of what you print. Here's how to make sure that the page numbers are, in fact, in sequential order. (This tip works with MS Excel 2007.)

There are two approaches you can use to get the page numbering you want. By default, Excel determines what it feels is the best starting page number when printing a worksheet. If you print just a single worksheet, Excel starts the numbering at page 1. If you print multiple worksheets at the same time (create a selection set of worksheet tabs before you start printing), then Excel prints the worksheets sequentially, one after the other, and numbers the pages sequentially as well.

Thus, to get the sequential page numbers you want, you should either select the worksheets you want to print before issuing a single print command or you should display the Print dialog box and, using the Entire Workbook radio button, specify that you want to print the entire workbook.

The second approach is to specify, manually, what page number you want Excel to use for a beginning page number. This approach works well when you can't print all your worksheets at once or if the worksheets you need to print are in separate workbooks. All you need to do is display the Page Setup dialog box (display the Page Layout tab of the ribbon and click the small icon at the bottom-right of the Page Setup group) and use the First Page Number box to specify what page number you want Excel to use.

One final note: You'll want to make sure that you have the headers or footers of your worksheets set up to actually include page numbers. Excel doesn't print them automatically; you need to specify that the header or footer contain a page number.

Posted courtesy of Tips.Net

Shortcuts to Hide Columns

Need a quick way to hide and unhide columns in a worksheet? The shortcuts described in this tip can help fill the bill. (This tip works with MS Excel 2007.)

In older versions of Excel, Ctrl+0 would hide selected columns and Ctrl+Shift+0 to unhide those columns. When upgrading to Excel 2007, however, only Ctrl+0 works, not Ctrl+Shift+0. Some people wonder if Microsoft changed one shortcut but not the other.

There was no change in the shortcuts; they both still work just fine in Excel 2007. If the second shortcut (Ctrl+Shift+0) doesn't work on your system, it could be because there is some add-in being loaded that stops the shortcut from working properly or, perhaps, because a custom shortcut key has been defined that uses the same key press.

Another thing to keep in mind is that the only way that Ctrl+Shift+0 works is if you have at least one hidden column selected before you use it. For example, if you hide columns D and E, you can later unhide them by selecting columns C through F (which obviously includes the hidden columns) and then pressing the shortcut.

Finally, you should be aware that both of these shortcuts only work if you use the 0 key on the main keyboard. They won't work if you use the 0 key on the numeric keypad.

Posted courtesy of Tips.Net

Sunday, January 3, 2010

An Average that Excludes Zero Values

Excel allows you to use functions and formulas to analyze your data. One way you can analyze your data is to use the AVERAGE function to find out the average of a range of values; this concept is easy to grasp. What may not be as easy is how you get an average that excludes zero values within the range. (This tip works with MS Excel 2007.)

Many people know how to use the AVERAGE function to determine the average of a range of values. However, some would like to have the average determined based on the non-zero values in the range.

The worksheet function most suited to this purpose is to use AVERAGEIF. You can use it in this manner:

=AVERAGEIF(A1:A50,">0")

This function only includes in the average those cells that contain values greater than zero. If you want to also exclude blank cells, you should use the AVERAGEIFS function. This function differs from AVERAGEIF in that it allows you to specify multiple criteria that indicate which cells to average.

=AVERAGEIFS(A1:A50,A1:A50,">0",A1:A50,"<>""")

Of course, if you want to approach the problem "old school" (without using AVERAGEIF or AVERAGEIFS), then there are several ways you can proceed. The first is to remember how an average is calculated. It is defined as the sum of a range of values divided by the number of items in the range. Thus, you could figure the exclusionary average by simply making sure that the denominator (the number you are dividing by) does not include any zero values. For instance:

=SUM(A1:A50)/COUNTIF(A1:A50,"<>0")

This approach uses the COUNTIF function to determine the number of cells in the range (A1:A50) that don't contain zero. If this range contains not only zeros but also blank cells, and you don't want the blank cells figured into the result, then you need to use a more complex formula:

=SUM(A1:A50)/(COUNTIF(A1:A50,"<>0")-COUNTBLANK(A1:A50)-(COUNTA(A1:A50)-COUNT(A1:A50)))

The COUNTIF function counts cells that do not explicitly evaluate to 0, but it will count blank and text cells. The COUNTBLANK term adjusts for the blank cells and the difference between COUNTA and COUNT adjusts the total count for cells that contain text.

Of course you can also use an array formula to do your calculation:

=AVERAGE(IF(A1:A50<>0,A1:A50))

Remember that array formulas need to be entered by using the combination Ctrl+Shift+Enter. This array formula also excludes blanks or cells containing text.

All in all it is easier to use the AVERAGEIF or AVERAGEIFS functions. When would you not want to use them? When you need to share your workbook with users of Excel versions prior to Excel 2007. (This is when the functions were added to Excel.)

Posted courtesy of Tips.Net