Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 90 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
90
Dung lượng
593,67 KB
Nội dung
This custom number format has five placeholders and displays the value with five digits (no decimal point). This is a good format to use when the cell holds a zip code (in fact, this is the code actually used by the ZIP Code format in the Special category). When you format the cell with this number format and then enter a zip code such as 06604 (Bridgeport, CT), the value is displayed with the leading zero. If you enter this number into a cell with the General number format, it displays 6604 (no leading zero). Scroll through the list of number formats in the Custom category in the Format Cells dialog box to see many more examples. In many cases, you can use one of these codes as a starting point, and only slight customization will be needed. Parts of a Number Format String A custom format string enables you to specify different format codes for positive numbers, negative numbers, zero values, and text. You do so by separating the codes with a semicolon. The codes are arranged in the following structure: Positive format; Negative format; Zero format; Text format If you use only one section, the format string applies to all values. If you use two sections, the first section applies to positive values and zeros, the second to nega- tive values. If you use three sections, the first section applies to positive values, the second to negative values, and the third to zeros. The following is an example of a custom number format that specifies a differ- ent format for each of these types: [Green]General;[Red]General;[Black]General;[Blue]General This example takes advantage of the fact that colors have special codes. A cell formatted with this custom number format displays its contents in a different color, depending on the value. When a cell is formatted with this custom number format, a positive number is green, a negative number is red, a zero is black, and text is blue. If you want to apply cell formatting automatically (such as text or back- ground color) based on the cell’s contents, a better solution is to use Excel’s Conditional Formatting feature (available in Excel 97 or later). Chapter 19 discusses this feature. Appendix C: Using Custom Number Formats 739 4800-x AppC.F 8/27/01 12:00 PM Page 739 Custom Number Format Codes Table C-3 lists the formatting codes available for custom formats, along with brief descriptions. I use most of these codes in examples later in this appendix. TABLE C-3 CODES USED TO CREATE CUSTOM NUMBER FORMATS Code Comments General Displays the number in General format # Digit placeholder 0 (zero) Digit placeholder ? Digit placeholder . Decimal point % Percentage , Thousands separator E- E+ e- e+ Scientific notation $ - + / ( ) : space Displays this character \ Displays the next character in the format * Repeats the next character, to fill the column width _ (underscore) Leaves a space equal to the width of the next character “text” Displays the text inside the double quotation marks @ Text placeholder 740 Appendix C: Using Custom Number Formats Preformatting Cells Usually, you’ll apply number formats to cells that already contain values. You also can format cells with a specific number format before you make an entry. Then, when you enter information, it takes on the format that you specified. You can preformat specific cells, entire rows or columns, or even the entire worksheet. Rather than preformat an entire worksheet, however, you can change the number format for the Normal style (unless you specify otherwise, all cells use the Normal style). Change the Normal style by selecting Format → Style. In the Style dialog box, click the Modify button and then choose the new number format for the Normal style. 4800-x AppC.F 8/27/01 12:00 PM Page 740 Code Comments [color] Displays the characters in the color specified [COLOR n] Displays the corresponding color in the color palette, where n is a number from 0 to 56 [condition value] Enables you to set your own criteria for each section of a number format Table C-4 lists the codes used to create custom formats for dates and times. TABLE C-4 CODES USED IN CREATING CUSTOM FORMATS FOR DATES AND TIMES Code Comments m Displays the month as a number without leading zeros (1–12) mm Displays the month as a number with leading zeros (01–12) mmm Displays the month as an abbreviation (Jan–Dec) mmmm Displays the month as a full name (January–December) mmmmm Displays the first letter of the month (J–D) d Displays the day as a number without leading zeros (1–31) dd Displays the day as a number with leading zeros (01–31) ddd Displays the day as an abbreviation (Sun–Sat) dddd Displays the day as a full name (Sunday–Saturday) yy or yyyy Displays the year as a two-digit number (00–99) or as a four-digit number (1900–9999) h or hh Displays the hour as a number without leading zeros (0–23) or as a number with leading zeros (00–23) m or mm Displays the minute as a number without leading zeros (0–59) or as a number with leading zeros (00–59) s or ss Displays the second as a number without leading zeros (0–59) or as a number with leading zeros (00–59) [ ] Displays hours greater than 24 or minutes or seconds greater than 60 AM/PM Displays the hour using a 12-hour clock; if no AM/PM indicator is used, the hour uses a 24-hour clock Appendix C: Using Custom Number Formats 741 4800-x AppC.F 8/27/01 12:00 PM Page 741 Custom Number Format Examples The remainder of this appendix consists of useful examples of custom number for- mats. You can use most of these format codes as-is. Others may require slight mod- ification to meet your needs. Scaling Values You can use a custom number format to scale a number. For example, if you work with very large numbers, you may want to display the numbers in thousands (i.e., displaying 1,000,000 as 1,000). The actual number, of course, will be used in calcu- lations that involve that cell. The formatting affects only how it is displayed. DISPLAYING VALUES IN THOUSANDS The following format string displays values without the last three digits to the left of the decimal place, and no decimal places. In other words, the value appears as if it’s divided by 1,000 and rounded to no decimal places. #,###, A variation of this format string follows. A value with this number format appears as if it’s divided by 1,000 and rounded to two decimal places. #,###.00, Table C-5 shows examples of these number formats: 742 Appendix C: Using Custom Number Formats Where Did Those Number Formats Come From? Excel may create custom number formats without you realizing it. When you use the Increase Decimal or Decrease Decimal button on the Formatting toolbar, new number formats are created that appear on the Number tab of the Format Cells dialog box. (To access this dialog box, click Cells on the Format menu.) For example, if you click the Increase Decimal button five times, the following custom number formats are created: 0.0 0.000 0.0000 0.000000 A format string for two decimal places is not created because that format string is built-in. 4800-x AppC.F 8/27/01 12:00 PM Page 742 TABLE C-5 EXAMPLES OF DISPLAYING VALUES IN THOUSANDS Value Number Format Display 123456 #,###, 123 1234565 #,###, 1,235 –323434 #,###, –323 123123.123 #,###, 123 499 #,###, (blank) 500 #,###, 1 123456 #,###.00, 123.46 1234565 #,###.00, 1,234.57 –323434 #,###.00, –323.43 123123.123 #,###.00, 123.12 499 #,###.00, .50 500 #,###.00, .50 DISPLAYING VALUES IN HUNDREDS The following format string displays values in hundreds, with two decimal places. A value with this number format appears as if it’s divided by 100, and rounded to two decimal places. 0”.”00 Table C-6 shows examples of these number formats: TABLE C-6 EXAMPLES OF DISPLAYING VALUES IN HUNDREDS Value Number Format Display 546 0”.”00 5.46 100 0”.”00 1.00 Continued Appendix C: Using Custom Number Formats 743 4800-x AppC.F 8/27/01 12:00 PM Page 743 TABLE C-6 EXAMPLES OF DISPLAYING VALUES IN HUNDREDS (Continued) Value Number Format Display 9890 0”.”00 98.90 500 0”.”00 5.00 –500 0”.”00 –5.00 0 0”.”00 0.00 DISPLAYING VALUES IN MILLIONS The following format string displays values in millions, with no decimal places. A value with this number appears as if it’s divided by 1,000,000, and rounded to no decimal places. #,###,, A variation of this format string follows. A value with this number appears as if it’s divided by 1,000,000, and rounded to two decimal places. #,###.00,, Another variation follows. This adds the letter M to the end of the value. #,###,,M The following format string is a bit more complex. It adds the letter M to the end of the value — and also displays negative values in parentheses as well as display- ing zeros. #,###.0,,”M”_);(#,###.0,,”M)”;0.0”M”_) Table C-7 shows examples of these format strings: TABLE C-7 EXAMPLES OF DISPLAYING VALUES IN MILLIONS Value Number Format Display 123456789 #,###,, 123 1.23457E+11 #,###,, 123,457 744 Appendix C: Using Custom Number Formats 4800-x AppC.F 8/27/01 12:00 PM Page 744 Value Number Format Display 1000000 #,###,, 1 5000000 #,###,, 5 –5000000 #,###,, –5 0 #,###,, (blank) 123456789 #,###.00,, 123.46 1.23457E+11 #,###.00,, 123,456.7 1000000 #,###.00,, 1.00 5000000 #,###.00,, 5.00 –5000000 #,###.00,, –5.00 0 #,###.00,, .00 123456789 #,###,,”M” 123M 1.23457E+11 #,###,,”M” 123,457M 1000000 #,###,,”M” 1M 5000000 #,###,,”M” 5M –5000000 #,###,,”M” –5M 0 #,###,,”M” M 123456789 #,###.0,,”M”_); 123.5M (#,###.0,,”M)”;0.0”M”_) 1.23457E+11 #,###.0,,”M”_); 123,456.8M (#,###.0,,”M)”;0.0”M”_) 1000000 #,###.0,,”M”_); 1.0M (#,###.0,,”M)”;0.0”M”_) 5000000 #,###.0,,”M”_); 5.0M (#,###.0,,”M)”;0.0”M”_) –5000000 #,###.0,,”M”_); (5.0M) (#,###.0,,”M)”;0.0”M”_) 0 #,###.0,,”M”_); 0.0M (#,###.0,,”M)”;0.0”M”_) Appendix C: Using Custom Number Formats 745 4800-x AppC.F 8/27/01 12:00 PM Page 745 ADDING ZEROS TO A VALUE The following format string displays a value with three additional zeros and no decimal places. A value with this number format appears as if it’s rounded to no decimal places and then multiplied by 1,000. #”,000” Examples of this format string, plus a variation that adds six zeros, are shown in Table C-8. TABLE C-8 EXAMPLES OF DISPLAYING A VALUE WITH EXTRA ZEROS Value Number Format Display 1 #”,000” 1,000 1.5 #”,000” 2,000 43 #”,000” 43,000 –54 #”,000” –54,000 5.5 #”,000” 6,000 0.5 #”,000,000” 1,000,000 0 #”,000,000” ,000,000 1 #”,000,000” 1,000,000 1.5 #”,000,000” 2,000,000 43 #”,000,000” 43,000,000 –54 #”,000,000” –54,000,000 5.5 #”,000,000” 6,000,000 0.5 #”,000,000” 1,000,000 Hiding Zeros In the following format string, the third element of the string is empty, which causes zero value cells to display as blank: General;General;;@ 746 Appendix C: Using Custom Number Formats 4800-x AppC.F 8/27/01 12:00 PM Page 746 Appendix C: Using Custom Number Formats 747 This format string uses the General format for positive and negative values. You can, of course, substitute any other format codes. Displaying Leading Zeros To display leading zeros, create a custom number format that uses the 0 character. For example, if you want all numbers to display with 10 digits, use the number for- mat string that follows. Values with fewer than 10 digits will display with leading zeros. 0000000000 You also can force all numbers to display with a fixed number of leading zeros. The format string that follows, for instance, appends three zeros to the beginning of each number: “000”# In the following example, the format string uses the repeat character code (an asterisk) to apply leading zeros to fill the entire width of the cell: *00 Formatting Percentages Using a percent symbol (%) in a format string causes the cell to display in percent- age format. Note that the percent sign also appears in the formula bar. The following format string formats values less than or equal to 1 in Percentage format. Values greater than 1 and text are formatted using the General format. [<=1]0.00%;General When you mix cells with percent and normal formatting in a column, you may prefer to see the nonpercent values indented from the right so the values line up properly. To do so, apply the following number format to nonpercent cells. This for- mat string uses an underscore followed by the percent symbol. The result is a space equal to the width of the percent symbol. #.00_% Figure C-3 shows a worksheet that uses this number format for the nonpercent cells (the range C6:C12). 4800-x AppC.F 8/27/01 12:00 PM Page 747 Figure C-3: Use a custom number format to align numbers. Displaying Fractions Excel supports quite a few built-in fraction number formats (select the Fraction cat- egory). For example, to display the value .125 as a fraction with 8 as the denomi- nator, select As eighths (4/8) from the Type list (see Figure C-4). Figure C-4: Selecting a number format to display a value as a fraction You can use a custom format string to create other fractional formats. For exam- ple, the following format string displays a value in 50ths: # ??/50 The following format string displays a value in terms of fractional dollars. For example, the value 154.87 is displayed as 154 and 87/100 Dollars. 0 “and “??/100 “Dollars” 748 Appendix C: Using Custom Number Formats 4800-x AppC.F 8/27/01 12:00 PM Page 748 [...]... Excel newsgroups found on Microsoft’s news server TABLE D-1 MICROSOFT.COM’S EXCEL- RELATED NEWSGROUPS Newsgroup Topic microsoft.public .excel. programming Programming Excel with VBA or XLM macros microsoft.public .excel. 123quattro Converting 1-2-3 or Quattro Pro sheets into Excel sheets microsoft.public .excel. worksheet functions Worksheet functions microsoft.public .excel. charting Building charts with Excel. .. microsoft.public .excel. printing Printing with Excel microsoft.public .excel. queryDAO Using Microsoft Query and Data Access Objects (DAO) in Excel microsoft.public .excel. datamap Using the Data Map feature in Excel microsoft.public .excel. crashesGPFs Help with General Protection Faults or system failures Continued 761 4800-x AppD.F 762 8/27/01 12:00 PM Page 762 Appendix D: Additional Excel Resources TABLE... MICROSOFT.COM’S EXCEL- RELATED NEWSGROUPS (Continued) Newsgroup Topic microsoft.public .excel. misc General topics that do not fit one of the other categories microsoft.public .excel. links Using links in Excel microsoft.public .excel. macintosh Excel issues on the Macintosh operating system microsoft.public .excel. interopoledde OLE, DDE, and other cross-application issues microsoft.public .excel. setup Setting... Appendix D: Additional Excel Resources information, bug lists, fix lists, and more You have free and unlimited access to the Knowledge Base via the Internet The URL is: http://search.support.microsoft.com/kb/ Microsoft Excel Home Page The official home page of Excel is at: http://www.microsoft.com/office /excel Microsoft Office Tools on the Web For information about Office 2002 (including Excel) , try this... numeric keypad to enter the digits) If you’re using Excel 2002, you can determine these codes by using the Insert ¡ Symbol command (see Figure C-8) For earlier versions of Excel, use the Windows Character Map program 4800-x AppC.F 8/27/01 12:00 PM Page 755 Appendix C: Using Custom Number Formats Figure C-8: Use the Insert Symbol dialog box (in Excel 2002 only) to determine the codes for special symbols... microsoft.public .excel. setup Setting up and installing Excel microsoft.public .excel. templates Spreadsheet Solutions templates and other XLT files microsoft.public .excel. sdk Issues regarding the Excel Software Development Kit Searching Newsgroups Many people don’t realize that you can perform a keyword search on past newsgroup postings Often, this is an excellent alternative to posting a question to the... into these pages.) Excel Web Source This site, maintained by Chip Pearson, contains dozens of useful examples of VBA and clever formula techniques The URL is: http://www.cpearson.com /excel. htm Stephen Bullen’s Excel Page Stephen’s Web site contains some fascinating examples of Excel code, including a section titled “They Said It Couldn’t Be Done.” The URL is: http://www.bmsltd.co.uk /excel Spreadsheet... adjustable bins basic counting.xls Formulas that demonstrate basic counting techniques conditional summing.xls Formulas that demonstrate various ways to calculate conditional sums count unique.xls Formulas to count the number of unique entries in a range counting text in a range.xls Formulas that demonstrate various ways to count text in a range cumulative sum.xls Formulas to calculate a cumulative... depreciation.xls Formulas that demonstrate the use of Excel s depreciation functions Example 01-09 (NPV).xls Examples 1–9 Example 10- 12 (IRR).xls Examples 10 12 Example 13-15 (MIRR).xls Examples 13–15 Example 16 (FVSCHEDULE).xls Example 16 Chapter 13 accumulation schedule.xls An example accumulation schedule creating indices.xls Demonstrates how to create indices credit card calculations.xls Formulas to... An array formula that displays a calendar logical functions.xls Demonstrates how to use logical functions in an array formula multi-cell array formulas. xls Examples of array formulas that occupy multiple cells single-cell array formulas. xls Examples of array formulas that occupy a single cell sorted function.xls A custom VBA function that returns a sorted range sum every nth.xls An array formula to . enter the digits). If you’re using Excel 2002, you can determine these codes by using the Insert → Symbol command (see Figure C-8). For earlier versions of Excel, use the Windows Character Map. 744 Value Number Format Display 100 0000 #,###,, 1 5000000 #,###,, 5 –5000000 #,###,, –5 0 #,###,, (blank) 123456789 #,###.00,, 123.46 1.23457E+11 #,###.00,, 123,456.7 100 0000 #,###.00,, 1.00 5000000. character. For example, if you want all numbers to display with 10 digits, use the number for- mat string that follows. Values with fewer than 10 digits will display with leading zeros. 0000000000 You