18.11.2014 Views

Microsoft Office

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Performing Magic with Array Formulas 18<br />

This formula compares TheName to each cell in the NameList range. It builds a new array that consists of<br />

logical TRUE or FALSE values. The OR function returns TRUE if any one of the values in the new array is<br />

TRUE. The IF function uses this result to determine which message to display.<br />

A simpler form of this formula follows. This formula displays TRUE if the name is found and returns FALSE<br />

otherwise.<br />

{=OR(TheName=NameList)}<br />

Yet another approach uses the COUNTIF function in a non-array formula:<br />

=IF(COUNTIF(NameList,TheName)>0,”Found”,”Not Found”)<br />

Counting the number of differences in two ranges<br />

The following array formula compares the corresponding values in two ranges (named MyData and<br />

YourData) and returns the number of differences in the two ranges. If the contents of the two ranges are<br />

identical, the formula returns 0.<br />

NOTE<br />

{=SUM(IF(MyData=YourData,0,1))}<br />

The two ranges must be the same size and of the same dimensions.<br />

This formula works by creating a new array of the same size as the ranges being compared. The IF function<br />

fills this new array with 0s and 1s. (0 if a difference is found, and 1 if the corresponding cells are the same.)<br />

The SUM function then returns the sum of the values in the array.<br />

The following formula, which is simpler, is another way of calculating the same result:<br />

{=SUM(1*(MyDataYourData))}<br />

This version of the formula relies on the fact that:<br />

and<br />

TRUE * 1 = 1<br />

FALSE * 1 = 0<br />

Returning the location of the maximum value in a range<br />

The following array formula returns the row number of the maximum value in a single-column range<br />

named Data:<br />

{=MIN(IF(Data=MAX(Data),ROW(Data), “”))}<br />

The IF function creates a new array that corresponds to the Data range. If the corresponding cell contains<br />

the maximum value in Data, the array contains the row number; otherwise, it contains an empty string. The<br />

MIN function uses this new array as its second argument, and it returns the smallest value, which corresponds<br />

to the row number of the maximum value in Data.<br />

If the Data range contains more than one cell that has the maximum value, the row of the first maximum<br />

cell is returned.<br />

337

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!