=IF(LOOKUP(B2,A:A)=B2,LOOKUP(B2,B:B),NA())

=IF(INDEX(A:A,MATCH(B1,A:A))=B1,INDEX(B:B,MATCH(B1,A:A)),NA())

the results show that both take close to 1 microsecond to calculate (roughly in line with joeu2004’s 0.9 microseconds for RAND). Splitting the match part out into another cell actually takes twice as long – a little over 2 microseconds.

Presumably there’s overhead both in calculating an extra cell and in adding a layer to the dependency tree. So using a helper column only pays off if you have a sufficient number of repetitions of the formula to calculate.

]]>Not a lot in it…

]]>So a Single Match Column and 10 Index Columns referring to the MATCH column will be significantly faster than 10 MATCH/INDEX combos ]]>

When I correct for that the double VLookup is faster than Match/Index.

I have also modified my UDF to work as an array function which improves its performance substantially. Returning 50 rows it took 2.9 times longer, and for 100 rows this came down to 1.7 times, compared with the double VLookup on the spreadsheet.

]]>Very true. From tests on several hundred thousand rows, the cell formulas themselves only appear to take around a microsecond to calculate and that still doesn’t change much with INDEX/MATCH v double LOOKUP specifications. These results tend to agree with Jeff’s initial take that you’re losing out from splitting calculations into separate cells with well optimised functions like these but you won’t really notice unless you have such large lookup tables to fill.

One other point is that when there are multiple values equal to the lookup value, the lookup formula seems to go through the list in a linear (not binary) fashion. So if column A consists entirely of 1’s, filling down =LOOKUP(1,A:A) takes a lot longer than =LOOKUP(2,A:A).

]]>Using a modified version of the joeu200 routine, with the lookup functions in 50 rows, my match/index function really speeds up, and is 50-80% faster than the binary VLookup with check.

My procedure was much the same as yours, except I initially selected my lookup values so that they all had matches, and then I modified half of them so there was no match.

The ratio for (Match-Index)/(Exact VLookup) was about 6800 when all the lookup values had an exact match, and 10700 when half of the values did not have any match. That makes sense, because if there is no match the exact VLookup has to check the entire list.

My UDF times were of the same order of magnitude per lookup as the subroutine took for 50 lookups, so it looks like most of the time for the UDF was data transfer.

]]>My code is based on the routine from joeu2004 at http://www.mrexcel.com/forum/excel-questions/762910-speed-performance-measure-visual-basic-applications-function.html

This thread is worth a read, because it makes this important point: we cannot measure the performance of “a” formula simply by measuring one instance of the formula. (But that does depend on the nature of the formula and the situation that we are trying to measure. Sometimes we need to measure one instance of a formula, but increase the size of ranges that it references in order to overcome the effects of overhead.)

I’ll post my TimeFormula routine in the near future…I’m just making some additional tweaks.

]]>