Avatar of ouestque
ouestque
Flag for United States of America asked on

Excel 2007: VBA function faster than Match function

What is the VBA for a function that is faster than the Match function?
VBAMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
aikimark

8/22/2022 - Mon
Martin Liss

Please describe exactly what the function needs to do.
Norie

I don't think there is a function that's faster than MATCH, in fact a combination of INDEX/MATCH is often used instead of VLOOKUP.

What exactly are you doing?
ouestque

ASKER
Hey guys. I  am trying to create a User Defined Function that is faster than Match(). Is that possible?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ouestque

ASKER
So the UDF would need to basically do what the Match function does, but faster. Find the row number of a value in a range.
Norie

Using a UDF instead of native Excel functionality is more than likely going to be slower.
aikimark

You can do this.  However, you need to understand that the speed will be offset by any update activity to the range you are matching against.  Before we begin, a few questions.

1. How static is the match range?
2. How big is the match range?
3. What is the data type of the cell values in the match range?  (numbers, dates, string, other, mixed)
4. Do you need the exact functionality of the Match() function or just searching for exact matches?
5. Is your current match range sorted?  If not, you should test the Match() function performance with sorted data.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ouestque

ASKER
1. Match range on most sheets do not change. Nonetheless, on some sheets new records are added every week.
2. 50k rows.
3. String.
4. Just searching for exact matches.
5. Yes.
ASKER CERTIFIED SOLUTION
aikimark

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
aikimark

If we need to simulate the Match() function more exactly, the FasterMatch() function should probably return #N/A error instead of -1 in the not-found scenario.
ouestque

ASKER
Awesome solution aikimark!! Thank You!!
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
aikimark

It is possible to expand this solution to multiple ranges you want to do FasterMatch() upon.