1. Trang chủ
  2. » Công Nghệ Thông Tin

Excel 2002 Formulas phần 7 pps

86 152 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 86
Dung lượng 1,16 MB

Nội dung

Here’s how it works. Select an individual data point in a chart series (not the entire series) and then drag the point in the direction in which you want to adjust the value. As you drag the data marker, the corresponding value in the worksheet changes to correspond to the data point’s new position on the chart. If the value of a data point that you move is the result of a formula, Excel dis- plays its Goal Seek dialog box. Use this dialog box to specify the cell that Excel should adjust to make the formula produce the result that you pointed out on the chart. This technique is useful if you know what a chart should look like and you want to determine the values that will produce the chart. Obviously, this feature can be dangerous, because you inadvertently can change values that you shouldn’t — so exercise caution. Using Animated Charts Most people don’t realize it, but Excel is capable of performing simple animations using shapes and charts (animations require macros). Consider the XY chart shown in Figure 17-30. Figure 17-30: A simple VBA procedure turns this chart into an interesting animation. The x values (column A) depend on the value in cell A1. The value in each row represents the previous row’s value, plus the value in A1. Column B contains for- mulas that calculate the SIN of the corresponding value in column A. The follow- ing simple procedure produces an interesting animation. It simply changes the value in cell A1, which causes the values in the x and y ranges to change. Chapter 17: Charting Techniques 481 4800-x Ch17.F 8/27/01 11:58 AM Page 481 Sub AnimateChart() Range(“A1”) = 0 For i = 1 To 150 Range(“A1”) = Range(“A1”) + 0.035 Next i Range(“A1”) = 0 End Sub The companion CD-ROM contains a workbook that features this animated chart, plus several other animation examples. Creating a “Gauge” Chart Figure 17-31 shows what appears to be a new chart type that resembles a gauge. Actually, it’s a standard pie chart, but with one hidden slice. The hidden slice occu- pies 50 percent of the chart, and it was hidden by setting its fill color to transpar- ent and specifying no border. The pie chart uses the values in range A1:A3. Cell A1 contains the value 1, and this represents the hidden slice. Cell A2 contains the value that will appear in the gauge. Cell A3 contains this simple formula: =1-A2 Figure 17-31: Hiding one slice of a pie chart creates a gauge chart. 482 Part V: Miscellaneous Formula Techniques 4800-x Ch17.F 8/27/01 11:58 AM Page 482 Creating a “Clock” Chart Figure 17-32 shows an XY chart formatted to look like a clock. It not only looks like a clock, but it also functions like a clock. There is really no reason why anyone would need to display a clock such as this on a worksheet, but creating the work- book was challenging, and you may find it instructive. Figure 17-32: This fully functional clock is actually an XY chart in disguise. The chart uses four data series: one for the hour hand, one for the minute hand, one for the second hand, and one for the numbers. The last data series draws a cir- cle with 12 points. The numbers consist of manually entered data labels. (See the sidebar, “Plotting a Circle.”) The formulas listed in Table 17-2 calculate the data series for the clock hands (the range G4:L4 contains zero values, not formulas). TABLE 17-2 FORMULAS USED TO GENERATE A CLOCK CHART Cell Description Formula G5 Origin of hour hand =0.5*SIN((HOUR(NOW())+(MINUTE(NOW())/60)) *(2*PI()/12)) H5 End of hour hand =0.5*COS((HOUR(NOW())+(MINUTE(NOW())/60)) *(2*PI()/12)) Continued Chapter 17: Charting Techniques 483 4800-x Ch17.F 8/27/01 11:58 AM Page 483 TABLE 17-2 FORMULAS USED TO GENERATE A CLOCK CHART (Continued) Cell Description Formula I5 Origin of minute hand =0.8*SIN((MINUTE(NOW())+(SECOND(NOW())/60)) *(2*PI()/60)) J5 End of minute hand =0.8*COS((MINUTE(NOW())+(SECOND(NOW())/60)) *(2*PI()/60)) K5 Origin of second hand =0.85*SIN(SECOND(NOW())* (2*PI()/60)) L5 End of second hand =0.85*COS(SECOND(NOW()) *(2*PI()/60)) This workbook uses a simple VBA procedure, which recalculates the worksheet every second. In addition to the clock chart, the workbook contains a text box that displays the time using the NOW() function, as shown in Figure 17-33. Normally hidden, you can display this text box by deselecting the Analog clock check box. A simple VBA procedure attached to the check box hides and unhides the chart, depending on the status of the check box. Figure 17-33: Displaying a digital clock in a worksheet is much easier, but not as fun to create. The workbook with the animated clock example appears on the companion CD-ROM. The CD also includes a different version of this file that uses VBA procedures instead of formulas. 484 Part V: Miscellaneous Formula Techniques 4800-x Ch17.F 8/27/01 11:58 AM Page 484 When you examine the workbook, keep the following points in mind: ◆ The ChartObject, named ClockChart, covers up a range named DigitalClock — used to display the time digitally. ◆ The two buttons on the worksheet are from the Forms toolbar, and each has a VBA procedure assigned to it (StartClock and StopClock). ◆ The CheckBox control (named cbClockType) on the worksheet is from the Forms toolbar, not from the Control Toolbox toolbar. Clicking the object executes a procedure named cbClockType_Click, which simply toggles the Visible property of the ChartObject. When invisible, the digital clock is revealed. ◆ The chart is an XY chart with four data series. These series represent the hour hand, the minute hand, the second hand, and the 12 numbers. Chapter 17: Charting Techniques 485 Plotting a Circle You can create an XY chart that draws a perfect circle. To do so, you need two ranges, one for the x values and another for the y values. The number of data points in the series determines the smoothness of the circle. Or, you simply select the Smoothed line option in the Format Series dialog box (Patterns tab) for the data series. The example shown (available on the companion CD-ROM) uses 13 points to create the circle. If you work in degrees, generate a series of values such as the ones shown in column A. The series starts with 0 and has 30-degree increments. If you work in radians (column B), the first series starts with 0 and increments by π/6. Continued 4800-x Ch17.F 8/27/01 11:58 AM Page 485 ◆ The UpdateClock procedure executes when you click the Start Clock but- ton. This procedure determines which clock is visible and performs the appropriate updating. ◆ The UpdateClock procedure uses the OnTime method of the Application object. This method enables you to execute a procedure at a specific time. Before the UpdateClock procedure ends, it sets up a new OnTime event that occurs in one second. In other words, the UpdateClock procedure is called every second. ◆ The UpdateClock procedure uses some basic trigonometry to determine the angles at which to display the hands on the clock. Drawing with an XY Chart The final example has absolutely no practical value, but you may find it interesting (and maybe even a bit entertaining). The worksheet consists of an embedded XY chart, along with a number of controls. (These controls, from the Forms toolbar, are not ActiveX controls.) 486 Part V: Miscellaneous Formula Techniques Plotting a Circle (Continued) The ranges used in the chart appear in columns D and E. If you work in degrees, the formula in D3 is: =SIN(RADIANS(A3)) The formula in E3 is: =COS(RADIANS(A3)) If you work in radians, use this formula in D3: =SIN(A3) And use this formula in E3: =COS(A3) The formulas in D3 and E3 simply copy down to subsequent rows. To plot a circle with more data points, you need to adjust the increment value in columns A and B (or C and D if working in radians). The final value should be the same as those shown in row 15. In degrees, the increment is 360 divided by the number of data points minus 1. In radians, the increment is π divided by the number of data points minus 1, divided by 2. 4800-x Ch17.F 8/27/01 11:58 AM Page 486 The workbook demonstrating drawing with an XY chart appears on the companion CD-ROM. Clicking one of the arrow buttons draws a line in the chart, the size of which is determined by the step value, set with one of the Spin controls. With a little prac- tice (and patience) you can create simple sketches. Figure 17-34 shows an example. Figure 17-34: This drawing is actually an embedded XY chart. Clicking an arrow button executes a macro that adds two values to a range: an x value and a y value. It then redefines two range names (XRange and YRange) used in the chart’s SERIES formula. Particularly handy is the multilevel Undo button. Clicking this button simply erases the last two values in the range, and then rede- fines the range names. Additional accoutrements include the capability to change the color of the lines, and the capability to display smoothed lines. Summary This chapter presented details on the SERIES formula used in charts, and presented several examples of nonstandard charts that you can produce with Excel. The chap- ter also discussed various types of trendlines and provided techniques for plotting functions. It presented a variety of useful chart tips and techniques that you can adapt for use with your charts. The next chapter covers formula techniques with pivot tables. Chapter 17: Charting Techniques 487 4800-x Ch17.F 8/27/01 11:58 AM Page 487 4800-x Ch17.F 8/27/01 11:58 AM Page 488 Chapter 18 Pivot Tables IN THIS CHAPTER ◆ An introduction to pivot tables ◆ How to create a pivot table from a database ◆ How to group items in a pivot table ◆ How to create a calculated field or a calculated item in a pivot table EXCEL’S PIVOT TABLE FEATURE probably represents the most technologically sophis- ticated component in Excel. This chapter may seem a bit out of place in this book. After all, a pivot table does its job without using formulas. That’s exactly the point. If you haven’t yet discovered the power of pivot tables, this chapter will demon- strate how using a pivot table can serve as an excellent alternative to creating many complex formulas. About Pivot Tables A pivot table is essentially a dynamic summary report generated from a database. The database can reside in a worksheet or in an external file. A pivot table can help transform endless rows and columns of numbers into a meaningful presentation of the data. For example, a pivot table can create frequency distributions and cross- tabulations of several different data dimensions. In addition, you can display subtotals and any level of detail that you want. Perhaps the most innovative aspect of a pivot table lies in its interactivity. After you create a pivot table, you can rearrange the information in almost any way imaginable, and even insert special formulas that perform new calculations. You even can create post hoc groupings of summary items (for example, combine Northern Region totals with Western Region totals). As far as I can tell, the term pivot table is unique to Excel. The name stems from the fact that you can rotate (that is, pivot) the table’s row and column headings around the core data area to give you different views of your summarized data. One minor drawback to using a pivot table is that, unlike a formula-based sum- mary report, a pivot table does not update automatically when you change the source data. This does not pose a serious problem, however, since a single click of the Refresh toolbar button forces a pivot table to use the latest data. 489 4800-x Ch18.F 8/27/01 11:58 AM Page 489 A Pivot Table Example The best way to understand the concept of a pivot table is to see one. Start with Figure 18-1, which shows the data used in creating the pivot table in this chapter. Figure 18-1: This database is used to create a pivot table. This database consists of daily new-account information for a three-branch bank. The database contains 350 records, and tracks the following: ◆ The date that each account was opened ◆ The opening amount ◆ The account type (CD, checking, savings, or IRA) ◆ Who opened the account (a teller or a new-account representative) ◆ The branch at which it was opened (Central, Westside, or North County) ◆ Whether a new customer or an existing customer opened the account The workbook shown in Figure 18-1 also appears on the companion CD-ROM. 490 Part V: Miscellaneous Formula Techniques 4800-x Ch18.F 8/27/01 11:58 AM Page 490 [...]... choice in the first dialog box; Figure 18 -7 shows the dialog box that appears when you select an Excel list or database in Step 1 4800-x Ch18.F 8/ 27/ 01 11:58 AM Page 4 97 Chapter 18: Pivot Tables Figure 18 -7: In Step 2, you specify the data range If you place the cell pointer anywhere within the worksheet database when you select Data ¡ PivotTable Report, Excel identifies the database range automatically... pivot table (you can’t use a calculated item in the Data area) The formulas used to create calculated fields and calculated items are not standard Excel formulas In other words, you do not enter the formulas into cells Rather, you enter these formulas in a dialog box, and they are stored along with the pivot table data Beginning with Excel 2000, you can use an OLAP database as the source for a pivot... validation 4800-x Ch19.F 8/ 27/ 01 11:58 AM Page 513 Chapter 19 Conditional Formatting and Data Validation IN THIS CHAPTER N An overview of Excel s conditional formatting feature N Practical examples of using conditional formatting formulas N An overview of Excel s data validation feature N Practical examples of using data validation formulas THIS CHAPTER EXPLORES TWO VERY useful Excel features: conditional... Ch18.F 8/ 27/ 01 11:58 AM Page 5 07 Chapter 18: Pivot Tables Figure 18- 17: This data demonstrates calculated fields and calculated items Figure 18-18: This pivot table was created from the data in Figure 18- 17 Creating a Calculated Field in a Pivot Table Because a pivot table is a special type of data range, you can’t insert new rows or columns within the pivot table This means that you can’t insert formulas. .. formatting and data validation You may not think these features have much to do with formulas But as you’ll see, when you toss formulas into the mix, these features can perform some amazing feats Excel 97 introduced conditional formatting and data validation Therefore, this chapter does not apply if you use an earlier version of Excel Conditional Formatting Conditional formatting enables you to apply cell... an Excel list or database 495 4800-x Ch18.F 496 8/ 27/ 01 11:58 AM Page 496 Part V: Miscellaneous Formula Techniques Pivot Table Data Sources The data used in a pivot table can come from a variety of sources, including Excel databases or lists, data sources external to Excel, multiple tabled ranges, and other pivot tables I describe these sources here Excel List or Database Usually, the data that you... into the worksheet You cannot use this technique with versions prior to Excel 2000 Also, note that Excel 2000 doesn’t have a PivotTable Field List toolbar Rather, the fields are displayed as buttons on the PivotTable toolbar 499 4800-x Ch18.F 500 8/ 27/ 01 11:58 AM Page 500 Part V: Miscellaneous Formula Techniques Pivot Table Options Excel provides plenty of options that determine how your pivot table looks... name for the pivot table Excel provides default names in the form of PivotTable1, PivotTable2, and so on N Grand totals for columns: Check this box if you want Excel to calculate grand totals for items displayed in columns N Grand totals for rows: Check this box if you want Excel to calculate grand totals for items displayed in rows N AutoFormat table: Check this box if you want Excel to apply one of... pivot table Excel uses the AutoFormat even if you rearrange the table layout N Subtotal hidden page items: Check this box if you want Excel to include hidden items in the page fields in the subtotals N Merge labels: Check this box if you want Excel to merge the cells for outer row and column labels Doing so may make the table more readable N Preserve formatting: Check this box if you want Excel, when... field Because the Units Sold field contains a space, Excel adds single quotes around the field name After you create the calculated field, Excel adds it to the Data area of the pivot table You can treat it just like any other field, with one exception: You can’t move it to the Page, Row, or Column area (it must remain in the Data area) 4800-x Ch18.F 8/ 27/ 01 11:58 AM Page 509 Chapter 18: Pivot Tables Figure . covers formula techniques with pivot tables. Chapter 17: Charting Techniques 4 87 4800-x Ch 17. F 8/ 27/ 01 11:58 AM Page 4 87 4800-x Ch 17. F 8/ 27/ 01 11:58 AM Page 488 Chapter 18 Pivot Tables IN THIS. =0.5*COS((HOUR(NOW())+(MINUTE(NOW())/60)) *(2*PI()/12)) Continued Chapter 17: Charting Techniques 483 4800-x Ch 17. F 8/ 27/ 01 11:58 AM Page 483 TABLE 17- 2 FORMULAS USED TO GENERATE A CLOCK CHART (Continued) Cell. “Plotting a Circle.”) The formulas listed in Table 17- 2 calculate the data series for the clock hands (the range G4:L4 contains zero values, not formulas) . TABLE 17- 2 FORMULAS USED TO GENERATE

Ngày đăng: 14/08/2014, 06:22

TỪ KHÓA LIÊN QUAN