We had already submitted the search function () in a series of articles commencing on 18 March 2006, so within six first months of this blog. This shows the importance of this function, which was one of 32 functions Visicalc (cons about 347 for Excel 2007), the ancestor of all spreadsheets, born in 1979.
It is time to propose a new tutorial for this basic function. We will resume the same example, discounted at current postal rate. You must mail a letter of 116 grams, using the rate in A2: B10.
course, you could use the formula in B13:
It can work, but this solution has three drawbacks: ●can not nest more than 7 functions;
● if we create a new category, for example per 160 grams, the formula must be changed: it is not flexible;
●a formula like this is particularly indigestible: it is hardly auditable.
The solution is to use the formula displayed in cell A13 commentary. But you can also use the formula in A14, which itself refers to Table transposed A16: B17. The syntax of the search function () is: search = (value, matrix) . We shall see in another article, a second form - added in later years - is also possible.
The algorithm of the search function ()
The algorithm used by the search function () is shown by the arrow lines plotted in blue. Excel compares 116 gr. 0 gr. then 20 gr. and then to 50 gr. until stumbling to a value greater than the reference value (in our case, we run on 250 gr.). When it finds the first value higher, it goes back a line followed by the far right in this line until the end of the reference matrix.
If the array is horizontal, Excel goes to the right until you find the first value above the reference value and then returns a column on the left and descends to the bottom of the matrix to find the result.
Note 1 - If the matrix is square, it is considered "vertical".
Note 2 - This algorithm assumes that the first column (vertical array) or the first line (horizontal array) consists of increasing values.
Note 3 - Warning! If you insert columns within the matrix, a matrix " vertical " can become "horizontal " , in which case the search sets will no longer give good results ...
0 comments:
Post a Comment