Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Power excel 2016 with mrexcel Master Pivot Tables, Subtotals, Charts, VLOOKUP, IF, Data Analysis in Excel 2010–2013 (Bill Jelen) (z-lib.org).pdf
Скачиваний:
4
Добавлен:
14.08.2022
Размер:
49.75 Mб
Скачать

144

POWER EXCEL WITH MR EXCEL

 

 

t Figure 359 Convert from Roman back to Arabic.

Factorials: The last obscure function you need to help with the math homework is the factorial function, FACT. A factorial is a number multiplied by every integer between itself and 1. To write 5 factorial, you use the number followed by an exclamation point. So, for example, 5! is 5 x 4 x 3 x 2 x 1, or 120. Use =FACT(5) to calculate 5!.

Figure 360 The factorial of 5 is 5 x 4 x 3 x 2 x 1, or 120.

CONVERT UNITS

Problem: I need to convert units of measure. I can never remember that there are .453 kilograms in a pound or 2.54 centimeters in an inch.

Strategy: You can use the CONVERT function to convert a certain number of one unit to another unit.

The CONVERT function works with units of weight, distance, time, pressure, force, energy, power, magnetism, temperature, and liquid measure.

The syntax for this function is =CONVERT(number, from unit, to unit). It’s important that you use the correct abbreviations (for example, lbm for pounds mass), so look in Excel help if you need to.

This figure shows a sampling of the conversions possible with this function.

Figure 361 CONVERT handles many conversion factors.

PART 2: CALCULATING WITH EXCEL

145

 

 

XOR ONLY WORKS CORRECTLY FOR TWO VALUES

Problem: Excel 2013 introduced an Exclusive OR (XOR) function. It won’t work correctly for more than two values.

Figure 362 Flo ordered three items, but XOR incorrectly returns TRUE.

 

Strategy: Blame it on Electrical Engineers. They use XOR chips in circuits. Despite it’s name, the XOR

 

chip counts if an odd number of inputs are TRUE. The Excel team decided to emulate the chip instead of

 

English. To truly do what all non-EE’s understand to be XOR, you could use =COUNTIF(B7:I7,True)=1.

2

 

 

 

FIND THE SECOND LARGEST VALUE

Problem: I can find the largest and smallest numbers using MAX and MIN. I am trying to identify the largest and smallest three numbers. How can I find the second largest number?

Strategy: Use the LARGE or SMALL functions. These functions take a range of values, then a k value. If you use a k value of 1, the LARGE function is exactly like a MAX: =LARGE(B2:B100,1). The real value in LARGE is the ability to ask for the second largest value using =LARGE(B2:B100,2).

In the figure below, you can see the LARGE and SMALL for an entire set of 10 data points. Note that 66 is reported as both the 5th and 6th largest value due to two 66 entries in the original data set.

Figure 363 Use LARGE and SMALL to return the kth largest value.

FORMAT EVERY OTHER ROW IN GREEN

Problem: Got any cool uses for MOD? Got any old-school methods for applying the greenbar format that was in the Excel 2003 AutoFormat dropdown?

146

POWER EXCEL WITH MR EXCEL

 

 

Strategy: This topic is about an out-of-the-box method for using MOD to apply a format. If the only goal was to apply alternate-row shading, you could use any of these methods:

● Alt+O+A and choose the Excel 2003 format. ● Ctrl+T, choose Banded Rows and any format.

Leave row 2 unformatted. Fill row 3 with green. Select row 2 & row 3. Use the fill handle to drag to the bottom of the data set. Open the Paste Options menu and choose Fill Formatting Only.

However, this topic is going to use math to do the formatting.

Consider the ROW function. =ROW(A2) will return 2 because A2 is in the second row of the worksheet. Here is a big range of ROW functions.

Figure 364 The ROW function tells you the row number.

Now, imagine taking all of those row numbers and dividing by 2. Throw away any integer result, but keep the remainder. This is a strange thought. All of the even number rows will not have a remainder at all. For the odd number rows, say that you take seven divided by 2. You get 3 with a remainder of 1. Throw out the 3 and keep only the remainder. The MOD function will give you only the remainder. =MOD(ROW(A7),2) will return a 1 because 7 divided by 2 has a remainder of 1. The next figure shows the MOD formula for several rows. Notice that you get stripes of 0’s and 1’s.

Figure 365 MOD of the ROW, 2 will return stripes.

So, how do you use this formula to add a green stripe in every other row? You do it with old-school conditional formatting. Follow these steps.

1. Select your range of data. Perhaps it is A2:G900.

2. Make a note of which cell is the active cell. This is the cell address that is shown in the Name box, to the left of the formula bar. You will need this cell address in step 4.

3. Select Home, Conditional Formatting, New Rule.

4. There are six types of rules listed in the top of the New Formatting Rule dialog. Choose the last type, called Use A Formula To Determine Which Rows To Format. When you choose this type, a formula bar appears in the bottom of the dialog. It is called Format Values Where This Formula is True.

5. Click in that formula box. Type a formula similar to this formula, but use the cell address from step

2 instead of A2. =MOD(ROW(A2),2)=1.

6. Click the Format… button.

7. On the Fill tab, choose a fill color. Click OK.

PART 2: CALCULATING WITH EXCEL

147

 

 

2

Figure 366 Your dialog should look like this one.

8. Click OK to apply the rule.

The range will be filled with an every-other row format.

Figure 367 Greenbar format.

The cool part is that if you delete a row or insert a row, the MOD(ROW(),2) formulas will recalculate and the shading will redraw. In the figure below, Line 3a is now green and Line 4 is white.

Figure 368 The formatting recalcs after inserting rows.

Additional Details: With a little math reasoning, you can change the format pattern. What if you wanted the even rows to be formatted? Change the formula to =MOD(ROW(A2),2)=0. If you wanted two rows of green followed by two rows of white, use =MOD(ROW(A2),4)>1.